Search code examples
blockchainethereumnft

How is a NFT Token ID assigned to an object (e.g., picture, tweet, video, etc.)


Background: Suppose I want to verify the ownership of some tweet or some picture by looking up the data in the blockchain. If my understanding is correct, I need to be able to assign a unique tokenId that represents that tweet/picture.

Question 1: Is there some standardization on how this ID is assigned? Do different platform perform this mapping in a unique way? I feel like without such a standardization, the non-fungibility becomes questionable (e.g., do you really own this tweet, or do you only own it if you apply the tweet->token ID mapping you crafted yourself?).

Question 2: Could you provide a few examples of how exactly is the token ID assigned to some (well-known) NFTs?


Solution

  • Is there some standardization on how this ID is assigned?

    The ERC-721 standard explicitly states that there is no standard to assign the ID (except for the uint256 datatype):

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


    e.g., do you really own this tweet, or do you only own it if you apply the tweet->token ID mapping

    Token ownership does not mean that you own the underlying resource. It only means that you own the token (representing the resource).


    Could you provide a few examples of how exactly is the token ID assigned to some (well-known) NFTs?

    • CryptoKitties - link, line 412, incrementing

      uint256 newKittenId = kitties.push(_kitty) - 1;
      
    • CryptoPunks - link, lines 73 and 83, assigning ID set by the (authorized) caller

      mapping (uint => address) public punkIndexToAddress;
      
      function setInitialOwner(address to, uint punkIndex) {
          // ...
          punkIndexToAddress[punkIndex] = to;