I'm following OpenZeppelin ERC721 guide. They use a counter (Counters.Counter) for the tokenId. My contract inherits from ERC721Enumerable so I have totalSupply() out of the box.

I was wondering if I could use totalSupply() instead of counter.current() when I mint a token and if that would be a good idea.

1 Answer 1


In fact, totalSupply() is just the convention function name in ERC 721 to a method that returns the totalSupply. You can override it to return the counter.current() or use a different approach/value.

Check this example in OpenZeppelin repo: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Enumerable.sol#L45

  • I'm using OpenZeppelin ERC721Enumerable contract so I have totalSupply() out of the box. So my question is if should I add a counter or just use totalSupply() as my counter when I mint a token.
    – Hector T.
    Commented Jan 4, 2022 at 22:05

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.