Skip to main content

How to get ERC20 token metadata by token addresses

Prerequisites​

Before getting started, make sure you have the following ready:

  • Node v.14+ or Python
  • NPM/Yarn or Pip

Step 1: Setup Moralis​

First register your Moralis account and get your Moralis API Key.

Once you have your Moralis API Key, install the Moralis SDK in your project.

npm install moralis @moralisweb3/common-evm-utils

Step 2: Get ERC20 Token Metadata By Multiple Token Addresses​

In order to an ERC20 token metadata, Moralis provides you a getTokenMetadata API endpoint to do so.

Here you'll need two parameters: addresses and chain.

Once you've obtained both the addresses and chain, you can copy the following code:

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/evm-utils");

const runApp = async () => {
await Moralis.start({
apiKey: "YOUR_API_KEY",
// ...and any other configuration
});

const addresses = [
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"0x514910771AF9Ca656af840dff83E8264EcF986CA",
];

const chain = EvmChain.ETHEREUM;

const response = await Moralis.EvmApi.token.getTokenMetadata({
addresses,
chain,
});

console.log(response.toJSON());
};

runApp();

Step 3: Run the script​

To run the script, enter the following command:

node index.js

In your terminal, you should see the following JSON response:

[
{
"address": "0x514910771af9ca656af840dff83e8264ecf986ca",
"name": "Chain Link",
"symbol": "LINK",
"decimals": "18",
"logo": "https://cdn.moralis.io/eth/0x514910771af9ca656af840dff83e8264ecf986ca.webp",
"logo_hash": "fd74ea1227adb458733847c09aab05d89c35c14b640c5ee1e0a8bffa79193eb4",
"thumbnail": "https://cdn.moralis.io/eth/0x514910771af9ca656af840dff83e8264ecf986ca_thumb.webp",
"block_number": null,
"validated": null,
"created_at": "2022-01-20T10:39:55.818Z"
},
{
"address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"name": "Wrapped Ether",
"symbol": "WETH",
"decimals": "18",
"logo": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.webp",
"logo_hash": "0a7fc292596820fe066ce8ce3fd6e2ad9d479c2993f905e410ef74f2062a83ec",
"thumbnail": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2_thumb.webp",
"block_number": null,
"validated": null,
"created_at": "2022-01-20T10:39:55.818Z"
}
]

Congratulations 🥳 you just got the price of an ERC20 metadata by multiple token addresses with just a few lines of code using the Moralis Token API!

API Reference​

If you want to know more details on the endpoint and optional parameters, check out:

Support​

If you face any trouble following the tutorial, feel free to reach out to our community engineers in our Discord or Forum to get 24/7 developer support.