How to Implement Token URI

In this tutorial, we will be exploring the implementation of Token URI in the Binance Smart Chain (BSC). Token URI is a feature that allows for the storage of additional information about a token, such as its description, image, or other relevant details. With Token URI, you can provide more context to the users about the tokens they hold, making it easier for them to understand and interact with them.

This tutorial will guide you through the steps to implement Token URI in Binance Smart Chain and how to access the information stored in it. By the end of this tutorial, you will have a solid understanding of Token URI and how to use it in your Binance Smart Chain-based projects.

Implementing Token URI

To facilitate a marketplace on BSC to pull in off-chain metadata for BEP721 assets, the NFT contract will need to return a URI where the metadata can be found. To find this URI, the tokenURI method in ERC721 and the uri method in ERC1155 are used to track your NFT. You should implement the function in the Contract:

 * @dev Returns an URI for a given token ID
function tokenURI(uint256 _tokenId) public view returns (string) {
  return Strings.strConcat(


The tokenURI function in your Contract should return an HTTP or IPFS URL. When queried, this URL should in turn return a JSON blob of data with the metadata for your token.

Metadata Structure

Marketplaces on BSC support metadata that is structured according to the official ERC721 metadata standard. Additionally, several properties for your items are supported, giving you all the sorting and filtering capabilities on BSC Marketplaces. The below metadata structure, allows the BSC Marketplace to read and display the details about the assets which your NFTs represent.

    "name":"NFT Name",
    "description":"NFT Description",


Here’s how each of these properties work:







Name of the item. Max 200 characters.


A human-readable description of the item. Markdown is supported. Max 500 characters.


This is the URL to the image of the item. It can be just about any type of image. A 350 x 350 image is recommended.


This is the URL to a multi-media attachment for the item. The file extensions GLTF, GLB, WEBM, MP4, M4V, OGV, and OGG are supported, along with the audio-only extensions MP3, WAV, and OGA.


This is the file format of the multi-media attachment provided from animation_url.


This is the URL that will appear below the asset’s image on the marketplace and will allow users to leave the marketplace and view the item on your site.


These are the attributes for the item to describe the detail of the NFT. (see array below)



To present NFT traits, include the following array in the metadata:

            "trait_type":"Rarity Class",
            "trait_type":"Health Increase",


Here trait_type is the name of the trait, value is the value of the trait, and display_type is a field indicating how you would like a numeric value should be displayed. For string traits, you don’t have to worry about display_type. All traits included in the attributes will be displayed in Attribute. If you don’t want to have a trait_type for a particular trait, you can include just a value in the trait and it will be set as a generic attribute.

Numeric Traits

There are 3 supported options for display_type: number will show the value in pure number, boost_number allows you to show the number with a Plus or Minus symbol, and boost_percentage is similar to boost_number but will show a percent sign behind the number.


Marketplace also supports date traits in date display_type. Pass in a Unix timestamp as the value.

   "display_type": "date", 
   "trait_type": "birthday", 
   "value": 1608490000


With this, you complete this workshop successfully!!