hammerandpick

Step into the Mint NFT experience.

Take a dive into our fully functional demo page. Explore how the Smart Contract works, connect with it using Wagmi, and master a seamless user experience with React and Tailwind.

Guide


Contract Summary


The AllowlistNFT.sol smart contract is an extension of an ERC721 smart contract. The ERC721A implementation is an extension of the ERC721 specification, and is optimized for gas savings and batch operations.

publicMint Explanation


The publicMint function allows anyone to mint an NFT from the contract so long as the mint is live and the allowlist time period has elapsed.

solidity
...

The above conditions correspond to the live and allowlistClose variables, respectively. These values are stored as state variables in the contract, and are set in the constructor.

The modifier whenLive is attached to the publicMint function, which checks the value of the live state variable to determine whether to revert the transaction or not.

solidity
...

The owner of the contract can call the toggleLive function to flip the boolean value of live, thus enabling and disabling minting NFTs.

Assuming live is set to true, the publicMint function will then ensure that the timestamp of the block being mined is greater than the timestamp stored in allowlistClose. Otherwise, the transaction will revert.

solidity
...

If the above check succeeds, then the requested number of NFTs to mint will be calculated and added to the total number of NFTs the caller (msg.sender) has minted previously. If this new total exceeds the maximum allowed NFTs to mint per-person or globally, then the transaction will revert.

solidity
...

Then, the function will check the supplied amount of ETH (msg.value) to ensure that enough ETH has been provided to mint the requested number of NFTs at the current price.

solidity
...

Assuming all these checks succeed, publicMint will then mint the specified amount of NFTs to the caller address.

solidity
...