How to get complete NFT metadata

NFT metadata is essentially the soul of an NFT, without it an NFT is nothing more than a record on the chain. That's why access to complete, up-to-date NFT metadata is so critical when creating Web3 experiences involving NFTs. In this tutorial we'll explain how to easily get this valuable component of your user experience with just a single API call. Before jumping into this tutorial we highly recommend getting familiar with unique properties, standards, and challenges associated with NFT metadata.

Mnemonic constantly indexes metadata for over 200 million NFTs (as of the time we wrote this guide) across blockchains and external IPFS and HTTP resources to provide the most fresh up-to-date metadata.

Mnemonic provides not only JSON formatted metadata, but also all kinds of metadata found on or off-chain.

The results provided by our API are normalized into a common schema to make it easy to work with.

Additionally, Mnemonic API provides raw metadata, which is returned in the raw field of the response. The raw value will include any sub-type of and including the text/plain mime-type of the document. Hence, in addition the mimeType field is provided to let the clients know what to expect (in most cases it's going to be application/json).

In order to get the full metadata of an NFT we will use the Token Metadata endpoint.

curlpythongo
Copy
Copied
curl -i -X GET \
  https://ethereum.rest.mnemonichq.com/tokens/v1beta1/token/0x1a92f7381b9f03921564a437210bb9396471050c/6582/metadata \
  -H 'X-API-Key: YOUR_API_KEY_HERE'
Copy
Copied
import requests # requires `pip install requests`

result = requests.get(
    'https://ethereum.rest.mnemonichq.com/tokens/v1beta1/token/0x1a92f7381b9f03921564a437210bb9396471050c/6582/metadata',
    headers={'x-api-key': 'YOUR_API_KEY_HERE'}
).json()
Copy
Copied
package main

import (
  "fmt"
  "net/http"
  "io/ioutil"
)

func main() {
  contractAddress := "0x1a92f7381b9f03921564a437210bb9396471050c";
  tokenId := "6582";
  reqUrl := "https://ethereum.rest.mnemonichq.com/tokens/v1beta1/token/" + contractAddress + "/" + tokenId + "/metadata"
  req, _ := http.NewRequest("GET", reqUrl, nil)
  req.Header.Add("X-API-Key", "YOUR_API_KEY_HERE")
  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := ioutil.ReadAll(res.Body)

  fmt.Println(res)
  fmt.Println(string(body))
}

The result will look something like this:

Copy
Copied
{
    "metadata": {
        "metadataUri": {
            "uri": "https://api.coolcatsnft.com/cat/6582",
            "mimeType": "application/json"
        },
        "name": "Cool Cat #6582",
        "description": "Cool Cats is a collection of 9,999 randomly generated and stylistically curated NFTs that exist on the Ethereum Blockchain. Cool Cat holders can participate in exclusive events such as NFT claims, raffles, community giveaways, and more. Remember, all cats are cool, but some are cooler than others. Visit [www.coolcatsnft.com](https://www.coolcatsnft.com/) to learn more.",
        "image": {
            "uri": "ipfs://QmToNpsJgWVdtbrFckzJVVskRrGXcJ6FsS2Gd9maGNWwQ2",
            "mimeType": "image/png"
        },
        "raw": "{\"name\": \"Cool Cat #6582\", \"image\": \"https://ipfs.io/ipfs/QmToNpsJgWVdtbrFckzJVVskRrGXcJ6FsS2Gd9maGNWwQ2\", \"points\": {\"Body\": 0, \"Face\": 1, \"Hats\": 1, \"Shirt\": 1}, \"attributes\": [{\"value\": \"blue cat skin\", \"trait_type\": \"body\"}, {\"value\": \"candle\", \"trait_type\": \"hats\"}, {\"value\": \"buttondown blue flannel\", \"trait_type\": \"shirt\"}, {\"value\": \"glossy\", \"trait_type\": \"face\"}, {\"value\": \"cool_1\", \"trait_type\": \"tier\"}], \"ipfs_image\": \"https://ipfs.io/ipfs/QmToNpsJgWVdtbrFckzJVVskRrGXcJ6FsS2Gd9maGNWwQ2\", \"description\": \"Cool Cats is a collection of 9,999 randomly generated and stylistically curated NFTs that exist on the Ethereum Blockchain. Cool Cat holders can participate in exclusive events such as NFT claims, raffles, community giveaways, and more. Remember, all cats are cool, but some are cooler than others. Visit [www.coolcatsnft.com](https://www.coolcatsnft.com/) to learn more.\", \"google_image\": \"https://drive.google.com/uc?id=1zfvGfwq3kPASergCKYw2Z_syq7NZEyu_\"}",
        "indexedAt": "2022-07-02T20:20:03.220133Z"
    }
}

As you can see, name, description, and image are provided as the top level fields for convenience. However, if you wish to to obtain the full metadata you should use the raw field, which is escaped JSON-encoded document.

The indexedAt field indicates the last time this metadata was indexed.

After you completed this tutorial, let us know about your experience or if you have any feedback by tagging us on Twitter @mnemonichq or reaching out directly to our support@mnemonichq.com!