I'm working on my ERC20 token and I'm in need of capping the total supply. For this purpose I found the ERC20Capped extension of ERC20 standard, but I noticed, that if I mint all my tokens (So reaching the cap) and then burn some, I would again be able to mint more tokens, because the total supply decreases when tokens are burned, but the token cap does not. What I would like to have is a token with a total cap (set at the contract creation like it is in ERC20Capped) so that I could not mint more than the cap, but also when any tokens are burned, it would decrease this token cap, in a way, achieving true deflation.

Is there a standard solution for such an ERC20 token, or I should get creative?

Easiest solution would be to mint all at contract creation and not have an external mint function, but I'd like to keep the possibility of minting in batches.

  • 1
    There is no reason why you could not create a token with any minting and burning rules you like. ERC-20 does not care.
    – user253751
    Dec 14, 2022 at 10:41

1 Answer 1


You can get creative. I am not 100% familiar with ERC20 contracts, but I can imagine it's similar to ERC721 in the way to limit the number of tokens.

First, just initialize a maximum number of tokens and a counter.

uint256 MAXCAP = 2000;
uint256 tokens = 0;

And for each new mint, increase the token counter.

tokens = tokens + 1;

and in your mint function, add a require statement that checks the number of minted tokens.

require(tokens < MAXCAP, "Maximum number of tokens already minted");

Then no new tokens can be minted because the MAXCAP is reached.

Another method is overriding the burn function to not decrease the amount of minted tokens, but that might also need a counter like above.

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.