ERC721LazyMint
ERC721LazyMint allows creators to lazy-mint ERC-721 tokens, i.e. allows any wallet to claim a lazy-minted NFT without the creator incurring in paying gas fees for minting.
Lazy minting allows creators to defer the actual minting of tokens until the moment they are purchased or claimed. This mechanism reduces upfront gas costs and enables a more scalable approach to issuing NFTs.
The ERC721LazyMint smart contract builds upon the ERC721Base by adding functionalities for lazy minting of ERC-721 tokens. Lazy minting enables the creation of token metadata ahead of time without incurring the gas costs associated with minting until the token is claimed.
ERC721LazyMint extends ERC721Base and integrates with the EIP712 standard for secure, typed, and verifiable messages to the blockchain.
Usage
import "@ninfa-labs/contracts/token/ERC721/presets/ERC721LazyMint.sol";This contract preset is itself inheriting from ERC721Base and extends it with the required functionality for lazy minting, it is not meant to be imported but rather used as standalone.
All the extensions used by ERC721Base are therefore inherited by ERC721LazyMint as well and can be accessed or overridden by this implementation. For example, the initialize function of the base contract is overridden in order to add the EIP712 extension, this is a required override since both contracts have the same function interface:
contract ERC721LazyMint is ERC721Base, EIP712 {
function initialize(bytes memory _data) public override(ERC721Base, EIP712) {
ERC721Base.initialize(_data);
// initialize Base contract before EIP712 because
// "name" metadata MUST to be set prior calling EIP712's initialize()
EIP712.initialize("");
}
constructor(address factory_) ERC721Base(factory_) { }
}Minting with Vouchers
The lazyMint function allows for minting tokens based on a pre-signed voucher from an authorized minter, using EIP712 typed signatures for added security.
Function Signature:
_voucher: Struct containing token metadata and minting details.
_signature: Digital signature proving the voucher's authenticity.
_data: Additional data that might be required by receiver contracts.
_to: Recipient of the minted token.
Buying with Lazy Minting
The lazyBuy function facilitates the purchase and immediate minting of a token based on a voucher. This function handles payment and ensures that the correct royalties are paid out as defined in the voucher.
Function Signature:
_voucher: Contains details such as price, token ID, and royalty information.
_signature: Signature for verifying the voucher's integrity.
_data: Data passed to recipient contracts.
_to: Buyer's address or the final recipient of the token.
Initialization and Setup
Upon deployment, ERC721LazyMint must be initialized with specific parameters that set up roles and configure metadata.
Initialization Override:
Initializes both
ERC721BaseandEIP712functionalities.Sets up essential metadata and roles required for the contract's operations.
Constructor
The constructor sets the factory contract address which is used when deploying clones of this contract, ensuring each instance knows its origin.
Constructor Signature:
factory_: Address of the factory contract used for deploying clones.
Conclusion
The ERC721LazyMint smart contract is an advanced tool for NFT creators looking to optimize and scale their minting processes. It leverages modern cryptographic standards to ensure security and efficiency, making it a powerful choice for projects requiring flexible minting and selling strategies. This guide should serve as a resource for deploying and interacting with ERC721LazyMint to take full advantage of lazy minting capabilities.
Last updated