Skip to main content

Lazy Mint

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

The LazyMint smart contract is an extension for any base NFT contract. It lets you 'lazy mint' any number of NFTs at once.

Here, 'lazy mint' means defining the metadata for particular tokenIds of your NFT contract, without actually minting a non-zero balance of NFTs of those tokenIds.

Availability in base contracts

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

Unlocked Features

By implementing LazyMint, you unlock the following features in the SDK and dashboard:

Implementing It Yourself

The LazyMint extension is an abstract contract, and expects you to implement the following functions by yourself:

NameTypeParametersReturnsDescription
_canLazyMintinternal view virtualn/aboolRuns on every attempt to lazy mint NFTs on the contract. Returns whether NFTs can be lazy minted in the given execution context.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

contract MyContract is LazyMint {
/**
* We store the contract deployer's address only for the purposes of the example
* in the code comment below.
*
* Doing this is not necessary to use the `LazyMint` extension.
*/
address public deployer;

constructor() {
deployer = msg.sender;
}

/**
* This function returns who is authorized to lazy mint NFTs on this contract.
*
* As an EXAMPLE, we'll only allow the contract deployer to lazy mint NFTs.
*
* You MUST complete the body of this function to use the `LazyMint` extension.
*/
function _canLazyMint() internal view virtual override returns (bool) {
return msg.sender == deployer;
}
}

Full API Reference

lazyMint

function lazyMint(
uint256 amount,
string calldata baseURIForTokens,
bytes calldata extraData
) external returns (uint256 batchId);
  • Lazy mints a given amount of NFTs.
  • Parameter amount: The number of NFTs to lazy mint.
  • Parameter baseURIForTokens: The base URI for the 'n' number of NFTs being lazy minted, where the metadata for each of those NFTs is baseURIForTokens/tokenId.
  • Parameter extraData: Additional bytes data to be used at the discretion of the contract.

_canLazyMint

function _canLazyMint() internal view virtual returns (bool);
  • Runs on every lazyMint function call.
  • Returns whether NFTs can be lazy minted in the given execution context.
  • For example, this function can check whether the wallet calling lazyMint is the contract owner, and enforce that only the owner should be able to successfully call lazyMint.