Skip to main content

Introduction

In this tutorial, you’ll learn how to retrieve detailed metadata for a specific NFT using its contract address and token ID. This includes the name, description, image, attributes/traits, and ownership information. This is essential for building NFT detail pages, verification tools, or collection browsers. We’ll use the following Moralis API endpoint:

Prerequisites

Step 1: Set Up Your Project

Create a new directory for your project and initialize it:
mkdir get-nft-metadata && cd get-nft-metadata
npm init -y

Step 2: Create the Script

Create a file called index.js and add the following code:
// index.js
const API_KEY = 'YOUR_API_KEY';
const NFT_ADDRESS = '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D'; // BAYC
const TOKEN_ID = '1234';

async function getNFTMetadata() {
  const response = await fetch(
    `https://deep-index.moralis.io/api/v2.2/nft/${NFT_ADDRESS}/${TOKEN_ID}?chain=eth`,
    {
      headers: {
        'X-API-Key': API_KEY,
      },
    }
  );

  const data = await response.json();
  console.log(JSON.stringify(data, null, 2));
}

getNFTMetadata();
Replace YOUR_API_KEY with your actual Moralis API key.

Step 3: Run the Script

Execute the script to fetch the NFT metadata:
node index.js

Example Response

{
  "token_address": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
  "token_id": "1234",
  "amount": "1",
  "owner_of": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
  "token_hash": "abc123def456...",
  "block_number_minted": "12346789",
  "contract_type": "ERC721",
  "name": "Bored Ape Yacht Club",
  "symbol": "BAYC",
  "token_uri": "ipfs://QmeSjSinHpPnmXmspMjwiXyN6zS4E9zccariGR3jxcaWtq/1234",
  "metadata": {
    "name": "Bored Ape #1234",
    "description": "A unique Bored Ape NFT",
    "image": "ipfs://QmRRPWG96cmgTn2qSzjwr2qvfNEuhunv6FNeMFGa9bx6mQ",
    "attributes": [
      { "trait_type": "Background", "value": "Aquamarine" },
      { "trait_type": "Fur", "value": "Blue" },
      { "trait_type": "Eyes", "value": "Bored" },
      { "trait_type": "Mouth", "value": "Grin" },
      { "trait_type": "Clothes", "value": "Sailor Shirt" }
    ]
  },
  "last_token_uri_sync": "2024-01-15T10:30:00.000Z",
  "last_metadata_sync": "2024-01-15T10:30:00.000Z",
  "minter_address": "0x1234567890abcdef...",
  "possible_spam": false,
  "verified_collection": true,
  "floor_price": 25.5,
  "floor_price_usd": 45000
}

Understanding the Response

FieldDescription
token_addressThe NFT collection contract address
token_idThe unique token ID
owner_ofCurrent owner’s wallet address
contract_typeToken standard (ERC721 or ERC1155)
nameCollection name
symbolCollection symbol
metadataRaw metadata from token URI
minter_addressAddress that originally minted the NFT
possible_spamWhether flagged as spam
verified_collectionWhether collection is verified
floor_priceCurrent collection floor price
floor_price_usdFloor price in USD

Next Steps