Skip to main content

Batch Mint Metadata

import "@thirdweb-dev/contracts/extension/BatchMintMetadata.sol";

The BatchMintMetadata smart contract is an extension for any base NFT contract. It lets the smart contract using this extension set metadata for n number of NFTs all at once. This is enabled by storing a single base URI for a batch of n NFTs, where the metadata URI for each NFT in a relevant batch is baseURI/tokenId.

Availability in base contracts

The BatchMintMetadata extension is already available in the following base contracts:

Implementing It Yourself

Import the extension smart contract and inherit it.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@thirdweb-dev/contracts/extension/BatchMintMetadata.sol";

contract MyContract is BatchMintMetadata {}

Full API reference

getBaseURICount

function getBaseURICount() public view returns (uint256);
  • Returns the total number of batches of NFTs, where each batch has a single base URI and metadata for NFTs in the batch is stored as baseURI/tokenId.
  • This value is updated when the metadata of a new set of NFTs is 'batch minted' using the _batchMintMetadata function.

getBatchIdAtIndex

function getBatchIdAtIndex(uint256 _index) public view returns (uint256);
  • The extension smart contract stores an array of 'batch IDs' i.e. IDs for different batches of NFTs minted on the contract. This function returns the batch ID at a given index in this ordered array of batch IDs.

_getBatchId

function _getBatchId(uint256 tokenId) internal view returns (uint256 batchId, uint256 index);
  • Returns the batch ID for the batch of NFTs the given tokenId belongs to.
  • Parameter tokenId: the tokenId for which to retrieve the associated batch ID.

_getBaseURI

function _getBaseURI(uint256 _tokenId) internal view returns (string memory);
  • Returns the base metadata URI for the given tokenId.
  • Parameter tokenId: the tokenId for which to retrieve the associated base metadata URI.

_setBaseURI

function _setBaseURI(uint256 batchId, string memory baseURI) internal;
  • Update the base metadata URI for a given batch of NFTs.
  • Parameter batchID: the batch ID of the batch of NFTs whose metadata URI is to be updated.
  • Parameter baseURI: the value to set as the new base URI for the relevant batch of NFTs.

_batchMintMetadata

function _batchMintMetadata(
uint256 _startId,
uint256 _amountToMint,
string memory _baseURIForTokens
) internal returns (uint256 nextTokenIdToMint, uint256 batchId);
  • Mints a batch of tokenIds and associates a common baseURI to all those Ids.
  • Parameter _startId: The lowest tokenId from the batch of NFTs to mint. It is assumed that token Ids are assigned to NFTs in a serial order, when batch minting e.g. [startId, startId + 1, ... n-1, n]
  • Parameter _amountToMint: The number of NFTs to mint at once.
  • Parameter _baseURIForTokens: The common base URI for the batch of NFTs being minted, where for a batch of NFTs with token IDs [startId, startId + 1, ... n-1, n], each NFT's associated metadata URI is [baseURI/startId, baseURI/startId+1, ... baseURI/n-1, baseURI/n]