Skip to main content

Introduction

In this tutorial, you’ll learn how to retrieve detailed metadata for any ERC20 token using the Moralis API. This includes the token name, symbol, decimals, logo, and more. This is useful for displaying token information in your application without needing to query the blockchain directly. 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-token-metadata && cd get-token-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 TOKEN_ADDRESS = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'; // USDC

async function getTokenMetadata() {
  const response = await fetch(
    `https://deep-index.moralis.io/api/v2.2/erc20/metadata?chain=eth&addresses=${TOKEN_ADDRESS}`,
    {
      headers: {
        'X-API-Key': API_KEY,
      },
    }
  );

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

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

Step 3: Run the Script

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

Example Response

[
  {
    "address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    "address_label": "USD Coin",
    "name": "USD Coin",
    "symbol": "USDC",
    "decimals": "6",
    "logo": "https://cdn.moralis.io/eth/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.png",
    "logo_hash": "a5d5d6eb25e2b5a8c26e7e47f7c6a2c8",
    "thumbnail": "https://cdn.moralis.io/eth/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_thumb.png",
    "total_supply": "26000000000000000",
    "total_supply_formatted": "26000000000",
    "block_number": "12345678",
    "validated": true,
    "created_at": "2018-09-10T00:00:00.000Z",
    "possible_spam": false,
    "verified_contract": true,
    "categories": ["stablecoin"],
    "links": {
      "website": "https://www.circle.com/usdc",
      "twitter": "https://twitter.com/circle"
    }
  }
]

Understanding the Response

FieldDescription
addressThe token’s contract address
nameThe full name of the token
symbolThe token’s ticker symbol
decimalsNumber of decimal places the token uses
logoURL to the token’s logo image
thumbnailURL to a smaller version of the logo
total_supplyTotal supply in the smallest unit
total_supply_formattedHuman-readable total supply
possible_spamWhether the token is flagged as potential spam
verified_contractWhether the contract source code is verified
categoriesToken categories (e.g., stablecoin, meme)
linksOfficial links (website, Twitter, etc.)

Next Steps