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.
1 Answer
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.
counter++
can do the same job withcounter.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.