Skip to main content

ERC721 Lazy Mint

import "@thirdweb-dev/contracts/base/ERC721LazyMint.sol";

ERC721LazyMint allows you to lazy-mint ERC-721 tokens, which allows any wallet to claim a lazy-minted NFT. It exposes a verifyClaim function that you can override to add your claim-restriction logic.

Lazy minting allows you to define the metadata of NFTs without minting it to an address. As a contract admin, this lets you prepare the metadata for NFTs that will be minted by other wallets, without paying the gas cost for actually minting the NFTs.

Detected Extensions

Once deployed, you can use the features made available by these extensions on the SDK and dashboard:

Click on each feature to learn more about what functions are available.

Usage

Import the contract and inherit from it.

// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "@thirdweb-dev/contracts/base/ERC721LazyMint.sol";

contract MyNFT is ERC721LazyMint {
constructor(
address _defaultAdmin,
string memory _name,
string memory _symbol,
address _royaltyRecipient,
uint128 _royaltyBps
) ERC721LazyMint(_defaultAdmin, _name, _symbol, _royaltyRecipient, _royaltyBps) {}

function verifyClaim(address _claimer, uint256 _quantity) public view virtual override {
// Your custom claim restriction logic
}
}

Functions to Override

The following functions have been implemented on this contract & are available to be overridden to add custom logic:

tokenURI
/**
* @notice Returns the metadata URI for an NFT.
* @dev See `BatchMintMetadata` for handling of metadata in this contract.
*
* @param _tokenId The tokenId of an NFT.
*/
function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) {
string memory batchUri = _getBaseURI(_tokenId);
return string(abi.encodePacked(batchUri, _tokenId.toString()));
}
claim
/**
* @notice Lets an address claim multiple lazy minted NFTs at once to a recipient.
* This function prevents any reentrant calls, and is not allowed to be overridden.
*
* Contract creators should override `verifyClaim` and `transferTokensOnClaim`
* functions to create custom logic for verification and claiming,
* for e.g. price collection, allowlist, max quantity, etc.
*
* @dev The logic in `verifyClaim` determines whether the caller is authorized to mint NFTs.
* The logic in `transferTokensOnClaim` does actual minting of tokens,
* can also be used to apply other state changes.
*
* @param _receiver The recipient of the NFT to mint.
* @param _quantity The number of NFTs to mint.
*/
function claim(address _receiver, uint256 _quantity) public payable nonReentrant {
require(_currentIndex + _quantity <= nextTokenIdToLazyMint, "Not enough lazy minted tokens.");
verifyClaim(msg.sender, _quantity); // Add your claim verification logic by overriding this function.

uint256 startTokenId = _transferTokensOnClaim(_receiver, _quantity); // Mints tokens. Apply any state updates by overriding this function.
emit TokensClaimed(msg.sender, _receiver, startTokenId, _quantity);
}
verifyClaim
/**
* @notice Override this function to add logic for claim verification, based on conditions
* such as allowlist, price, max quantity etc.
*
* @dev Checks a request to claim NFTs against a custom condition.
*
* @param _claimer Caller of the claim function.
* @param _quantity The number of NFTs being claimed.
*/
function verifyClaim(address _claimer, uint256 _quantity) public view virtual {}
burn
/**
* @notice Lets an owner or approved operator burn the NFT of the given tokenId.
* @dev ERC721A's `_burn(uint256,bool)` internally checks for token approvals.
*
* @param _tokenId The tokenId of the NFT to burn.
*/
function burn(uint256 _tokenId) external virtual {
_burn(_tokenId, true);
}
_transferTokensOnClaim
    /**
* @notice Mints tokens to receiver on claim.
* Any state changes related to `claim` must be applied
* here by overriding this function.
*
* @dev Override this function to add logic for state updation.
* When overriding, apply any state changes before `_safeMint`.
*/
function _transferTokensOnClaim(address _receiver, uint256 _quantity)
internal
virtual
returns (uint256 startTokenId)
{
startTokenId = _currentIndex;
_safeMint(_receiver, _quantity);
}