Solidity to set a cap on the amount of ERC721 tokens?

For I am not good at coding,so coud anyone tell me directly,how could set the maximum amount of a ERC721 token.Better give me a code example,I know it’s presumptuous and looks lazy. :hot_face:,But it does save me a lot of time.

1 Like

Hi @kate_king,

To implement you should do the following:

  • Have a state variable for the cap.
  • Set the cap in the constructor.
  • Have a getter so that the cap can be read.
  • In the mint function of your ERC721, check if the total number minted (you will need a count of this total supply) is less than the cap before minting.

ERC20Capped.sol shows how to do this for ERC20

For a counter you can use Counters

1 Like

Thank you@abcoathup
and do you have one for ERC721 smart contract ?

1 Like

Just take the exact same cap logic from his example and place it in an ERC721 contract. There’s nothing special which binds that code to ERC20 only.

It should work fine.

1 Like

nice and thanks a lot