0

I've been studying ERC721 token smart contracts and saw Counters library. I can see it being used when token is being minted with .increment() and then you can check total supply with .current(). But what's the point of it? It just adds some basic stuff and makes contract bigger, it's easier to make an uint variable and increment it with += 1 on mint and return it on totalSupply function.

3
  • 1
    It's just generally a good practice. Yes, counter++ can do the same job with counter.increment(), however, it adds readability to solidity especially when Solidity code is part of the marketing material for transparency. Not only professional coders can read it, but also rookies, outsiders, or investors. Readability matters.
    – Maxareo
    Mar 11 at 11:59
  • 1
    imo it obfuscates code. I am not a fan of it.
    – phaze
    Mar 11 at 12:19
  • I also find it less readable than just doing it manually and am not a fan. It feels bizarrely industrial for such a basic function.
    – Kyle Baker
    Apr 21 at 21:22

1 Answer 1

0

https://docs.openzeppelin.com/contracts/3.x/api/utils#Counters

Seems that one of the key feature is ensuring that its only ever incremented and decremented by 1. The readability is a plus as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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