Create a MAX SUPPLY to Mint ERC20

cpp-ethereumerc-20remixsolidityweb3js

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!

Best Answer

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.

Related Topic