0

I want to create an ERC20 on Solidity.

I want 1000 TOKENS of MAX SUPPLY (Like the 21m of bitcoin).

PERSON A: Mint to his wallet 700 Tokens. (Thats okey)

Only 300 Tokens are available.

PERSON B: Mint to his wallet 400 Tokens. (¡Error!)

How can i do it?

Thanks!

2 Answers 2

0

Keep MAX_SUPPLY as a variable in your Smart Contract that stores the maximum number of tokens that you wanna sell.

Also keep a TOKENS_SOLD variable in the Smart Contract that keeps track of how man tokens have been sold so far.

Before someone tries to mint some tokens, do the below

require(MAX_SUPPLY > TOKENS_SOLD + numberOfTokensToBeMinted, "Insufficient supply");

This should serve your purpose.

2
  • Thanks! thats is the best way to do it?? How can i get the numbers of tokens solds in a function??
    – Fr4nc0
    Commented Oct 26, 2021 at 0:10
  • thats is the best way to do it?? - Nothing is perfect. How can i get the numbers of tokens solds in a function?? - The TOKENS_SOLD will be global to your Contract. Commented Oct 26, 2021 at 4:04
0

There is an ERC20Capped contract that inherits from ERC20 and includes exactly the functionality that you want:

https://docs.openzeppelin.com/contracts/4.x/api/token/erc20#ERC20Capped

Reading that spec will give you everything you need to know about creating a max supply token that throws an error if someone tries to mint past the supply cap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.