First of all, sorry if I'm asking an obvious question.

In ERC721 openzeppelin API, to manage a token you always need to refer to a tokenId.

Are you supposed to define a global variable, or a mapping in the case of enumerable, in the contract to refer to tokenId? Is this the best way to go, or should you use any method to set tokenId?

  • Please share the relevant code. – goodvibration Dec 19 '20 at 11:50
  • when the token is generated it will get its token id: _mint(address to, uint256 tokenId) And the token id will be added to owner in this variable: mapping (address => EnumerableSet.UintSet) private _holderTokens; – Majd TL Dec 22 '20 at 9:13

A tokenId in EIP 721 is an unique arbitrary number you assign to each one of your tokens.

From the specification:

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”.

You can assign consecutive numbers starting from 0, or a more complex formula. If the numbers do not repeat you should be fine.

  • Thanks! Just wanted to be sure if there was a convention about that, or not. – AlexAcc Dec 20 '20 at 11:16

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