The ERC-721 specification indexes NFTs by a tokenId
, a variable of type uint256
.
Are there any best practices on how the ids should be generated?
For instance, is it fine to use a simple integer counter that starts at 1?
The ERC-721 specification indexes NFTs by a tokenId
, a variable of type uint256
.
Are there any best practices on how the ids should be generated?
For instance, is it fine to use a simple integer counter that starts at 1?
By reading the EIP-721 it mentions the NFT Identifiers.
It states:
While some ERC-721 smart contracts may find it convenient to start with ID 0 and simply increment by one for each new NFT, callers SHALL NOT assume that ID numbers have any specific pattern to them, and MUST treat the ID as a “black box”.
So anyway you choose as long as the identifier is unique is good by standard.
Yes, you can use integer counters to increment the tokenId
and because in Ethereum, transactions are processed sequentially (based on transaction gas fees chosen by the validators), the counters will work correctly.