Course lesson
Add a Mint Function to Your NFT Smart Contract
We need our users to be able to mint their NFT tickets. We also need to limit the number of available tickets.
- Duration
- 5 min
- Access
- Included
- Transcript
- Retained from source evidence
We need our users to be able to mint their NFT tickets. We also need to limit the number of available tickets.
Start by making sure each NFT has a unique ID. OpenZeppelin gives us the handy utility Counters for this. We will increment the ID each time an NFT is minted.
Once your NFTs have IDs you can use the inherited _safeMint function from OpenZeppelin in your mint function to mint an NFT for the initiator of the function. Also, make sure to increment the ID and decrement the number of remaining NFTs.