KCC Documents
  • Quickstart
  • Overview
    • Introduction
    • Features
    • Our Goal
    • Consensus Engine
    • Marketing Guide
      • Requirements
      • KCC Official Website Resource
      • KCC Social Media Promotion
      • PR & Third-Party Marketing Support
  • Developers
    • Network Endpoints
    • Deploy Smart Contract
      • Using Hardhat
      • Using Remix
    • Verify Smart Contract
      • Using Hardhat
      • Using Foundry
      • Using Remix
    • Issue ERC20 Token
    • Deploy NFTs
      • Create A Foundry Project
      • Create Your ERC721 Contract
      • Add Metadata
    • Run a Node
      • Hardware & System Requirements
      • Install KCC
      • Run A Full Node
      • Run A Validator Node
        • Block Rewards
        • Apply For Running A Validator
        • Manager Account And Validator Account
        • Run A Validator
      • Troubleshooting
    • Explorer
    • Oracles
      • KCC Oracle
    • Bridge
    • Dev Toolkit
    • Data
      • Indexing and Querying
        • The Graph
        • Using KCC's hosted subgraph
    • Gas Revenue Program
      • Rules for Calculation of Gas Revenue
      • How to Join the KCC Gas Revenue Program
  • Individuals
    • Wallet
      • Supported Wallet
      • Tutorial on how to set up wallet
      • Mutisig Wallet
        • Create New Safe
        • Send KCS From Your Safe
        • Use A DApp With Your Safe
    • Network Configuration
      • Configure Value
      • Tutorial on how to config KCC network in Metamask
      • Tutorial on how to config KCC network in Chainlist
    • Bridge Assets
      • Bridge assets from others chains
      • KCC Bridge
      • Bridge assets form Exchange
    • Find a dApp
      • Add Your dAPP
    • KCS Token
      • Get KCS
      • Stake KCS
        • How to participate in KCS Staking
        • How to redeem staked KCS
        • How to check or claim staking rewards
  • FAQs
    • FAQs
      • General FAQs
      • KCS and Staking FAQs
      • Validator FAQs
  • Future Developments
    • Milestone
  • CONTACT US
    • Contact Us
  • Disclosure
    • Disclaimers
    • Risk Statement
    • Media Kit
Powered by GitBook
On this page
  • Prepare Metadata
  • Set The Base URI
  1. Developers
  2. Deploy NFTs

Add Metadata

PreviousCreate Your ERC721 ContractNextRun a Node

Last updated 2 years ago

Following the previous two tutorials, we created our contract and minted an NFT with ID = 1337. However, our minted NFT has no metadata associated with it. Without metadata, an NFT token is nothing but a token with an ID.

Our smart contract implements the ERC721 meta extension, and it has the following method for getting the metadata URI of an NFT token:

    /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
    /// @dev Throws if `_tokenId` is not a valid NFT. URIs are defined in RFC
    ///  3986. The URI may point to a JSON file that conforms to the "ERC721
    ///  Metadata JSON Schema".
    function tokenURI(uint256 _tokenId) external view returns (string);

The tokenURI method returns a string which is the URI to the metadata of an NFT token. And the metadata is presented in a JSON file.

Prepare Metadata

The metadata of an NFT token is presented in a JSON file. Here is an example:

{
  "description": "My NFT", 
  "image": "https://example.com/1337.png", 
  "name": "Hacker's Token 1337",
  "attributes": [
    {
      "trait_type": "Mouth", 
      "value": "Surprised"
    }, 
    {
      "trait_type": "Level", 
      "value": 5
    }
  ]
}
  • name is the name of this item(i.e, this NFT token), because each NFT token may have a different name.

  • image is the link to the image of this NFT token.

  • description is a short description of this NFT token.

  • and attributes is a list of attributes that this NFT token has.

Note the link to the image is also in the metadata JSON. In this example, we are using an ordinary (web2) link. However, to make it more decentralized, you can upload your images to IPFS and use the IPFS CIDs with a gateway.

You should create one metadata JSON for each of your NFT tokens. Let's assume you are hosting all the metadata JSON files on the host of my-nft-metadata.com , and the metadata JSON of each NFT token should have the following format:

https://my-nft-metadata.com/1337
  • https://my-nft-metadata.com is called the base URI.

  • 1337 is the ID of the NFT token

Set The Base URI

After uploading all the metadata JSON files somewhere and hosting them with the same base URI, we can set the base URI of the contract. Again, we can use the cast command:

FOUNDRY_PROFILE=kcc_testnet \
        cast send  --private-key=XXXXXXXXXX  \
        --legacy \
        0xd382De234f8d3B35823f1DB54C85cE6498a9DbC84c \
        'setBaseURI(string)' "https://my-nft-metadata.com/"
  • XXXXXXXXX is your private key as usual

  • 0xd382De234f8d3B353f1DB54C85cE6498a9DbC84c is the address of our NFT contract.

  • And we use cast to call the setBaseURI method, and change the base URI to "https://my-nft-metadata.com"

Let's verify that our base URI works as expected. We use cast to get the tokenURI of the token of 1337:

FOUNDRY_PROFILE=kcc_testnet \
    cast call 0xd382De234f8d3B353f1DB54C85cE6498a9DbC84c \
    'tokenURI(uint256)(string)' 1337 

You should see the following URI printed out:

https://my-nft-metadata.com/1337

Apart from the commonly used fields in the above example, some other fields are also supported in the metadata JSON file. You can find more .

If you upload all your metadata JSON files to IPFS, you should add the whole directory that includes all the JSON files. Then, all the JSON files can be visited with the same base URI. For example, .

here
all the metadata JSON files of the BAYC collection share the same base URI