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.

info

In order for the ERC721LazyMintable, ERC1155LazyMintable or ERC20LazyMintable extension to be detected in the Dashboard, the corresponding ERC721, ERC1155 or ERC20 extensions need to be added alongside the LazyMint extension.


Usage

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

NameTypeReturnsDescription
_canLazyMintinternal view virtualboolRuns on every attempt to lazy mint NFTs on the contract. Returns whether NFTs can be lazy minted in the given execution context.

This is an example smart contract demonstrating how to inherit from this extension and override the functions to add (optional) custom functionality.

// 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;
}
}

SDK Usage

By adding this extension to a smart contract, the following features, hooks and functions are unlocked in the SDK (if combined with either ERC721 or ERC1155):

Base Contracts Implementing This Extension

(if combined with either ERC721 or ERC1155)

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.