When I first introduced game items as NFT tokens we have seen that on minting stage there is a possibility to add token's  tokenURI but I never used it in a reasonable way, instead, I've just input there some meaningless values.


Token's metadataURI is a way to assign some data to our game items and use it anywhere we want i.e:

  • on market
  • in a game

A meaningful URI

According to https://eips.ethereum.org/EIPS/eip-721 metadataURI should have the following fields name , description and image. Name and description are obvious however image field can be an image (like i.e. jpeg) or link to another file. However, it would be even more useful to implement enjin standard for this as it allows to specify attributes for game items :)

Edit: according to opensea the best way for this project would be to extend metadata of each token into special attributes that opensea understands and represent on its UI.

How it works

Each NFT token should have tokenURI set to URL (commonly IPFS) that resolves to metadata.json file. IPFS may be a good choice due to its benefits. Immutability is the special feature that shines when it is supposed to be traded.


The sword attributes

If we recall how the sword looks like it would be best if we have at least 4 fields in the metadata.

  • image of the sword
  • level of sword
  • Damage (hit points)
  • Agility

Knowing this metadata for the sword would be following:

Damage and agility should both be presented as progress bars, level will be just a number presented there. The config consumable by opensea UI will look like this:

Damage : {trait_type: "Damage","value":25, "max_value": 100}
Agility : {trait_type: "Agility","value":17, "max_value": 100}
Level: {trait_type: "Level", "value":1, "displa_type": number}


So complete of metadata will look like:

{
"Description": "Use the sword to eettle the score with pure evil",
"name": "Sword of Justice",
"attributes":[
	{"trait_type": "Damage","value":25, "max_value": 100},
	{"trait_type": "Agility","value":17, "max_value": 100},
	{"trait_type": "Level", "value":1, "display_type": "number"}
],
"image": "ipfs://content-based-path-to-image"
}

Uploading to IPFS

As there are two files related to the token we need to upload both of them to IPFS. Since metadata.json links to image file the sequence of uploading would be:

  1. Upload image file and note its path
  2. Reference image file in metadata.json using its path from point 1.
  3. Upload metadata.json file

After uploading it ifps and pinning thanks to pinata it look like this

And both those files can be accessed thanks to the pinata.cloud gateway (service that helps no compatible browsers see the ipfs resources as regular ones)

https://gateway.pinata.cloud/ipfs/QmP22uedqSAcbNqCzcXdnsEMfJr8QqjtTjX3zS71BkXfxx/sword-of-justice.png

https://gateway.pinata.cloud/ipfs/QmP22uedqSAcbNqCzcXdnsEMfJr8QqjtTjX3zS71BkXfxx/metadata.json

Time to assign tokenUri to a newly minted token

This is fairly easy again we can use etherscan for this and log in with metamask. Then on minting, we use not any value but a specific value of metadata.json located in ipfs (not the gateway address as this is not necessary and introduces single point of failure)

As denoted on the pic, first we log in with metamask then use mint function with our address as owner and ipfs link to metadata.json (that itself links to image)

Just as a reminder on how to mint new token in our smart contract on ehterscan.

This time however there is a need to use the ipfs URLinstead of meaningless value as in the movie.


Let's test stuff on Opensea

After login to test.opensea.io (that is on rinkeby test network, same as the contract and its token) we should see out NFT token in its full shape. It should have name and description as in metadata.json, should have the image uploaded to ipfs and additionally should have attributes as discussed above.

Just after log in it is presented on the list.

List of token with the very first one just minted with all params assigned
The way token attributes are presented on opensea ui

And we also can see its attributes presented by opensea internal UI:

  • level (1 of 1 the latter comes from analyzing all others and as there is just one this is how it is)
  • agility
  • damage

Wrapping-up

We discussed here

  • how are metadata linked to NFT token
  • what are metadata standards and how is opensea consuming them
  • uploaded metadata.json and pic to ipfs
  • how attributes rich token is presented on opensea