How to Get Token Metadata
Use Alchemy’s token API to get all the metadata for your ERC-20 token including name, symbol, and other important details
This tutorial uses the alchemy_getTokenMetadata endpoint.
Often when you are a DeFi app aggregating several tokens on your platform (like Uniswap), or an analytics app displaying data about thousands of tokens (like CoinGecko) - you need to show the metadata for several tokens. The metadata includes important fields like the token’s name, symbol, and logo.
Alchemy’s Token API endpoint getTokenMetadata
can come in handy for use-cases like that! In this tutorial, we will fetch the metadata for the USDT token.
For ERC721 or ERC1155 token metadata, check out the getNFTMetadata method.
How to query the metadata for a token
When querying the metadata for a token, you need one input parameter
contractAddress
This is the address of the token on the blockchain that you want to pull the metadata for.
Example: Get metadata for USDT token
For this particular example, we’re going to fetch the metadata for USDT token which has the contract address 0xdAC17F958D2ee523a2206206994597C13D831ec7
“
For a no-code view of the API request, check out the composer tool
Alchemy SDK (Recommended)
Step 1: Install the Alchemy SDK Quickstart and create a file
Run the below commands in the command line:
Step 2: Write the token metadata querying script
Inside the token-metadata-from-sdk.js
file, paste the below code
Step 3: Run the code to get the token metadata with the Alchemy SDK
You should see the below output:
Node-Fetch
Step 1: Create a node-fetch file
Run the below commands in the command line:
Step 2: Write the token metadata querying script
Inside the token-metadata-from-fetch.js
file, paste the below code
Step 3: Run the code to get the token metadata with Node-fetch
You should see the below output
Axios
Step 1: Install axios and create a file
Run the below commands in the command line
Step 2: Write the token metadata querying script
Inside the token-metadata-from-axios.js
file, paste the below code
Step 3: Run the code to get the token metadata with Axios
You should see the below output
In the above steps, you can replace the tokenAddr
with any token’s contract address to get its metadata!
Understanding the API response
Raw API response:
decimals
: the lowest atomic unit of a token; The smallest amount of that token that can be exchanged between two addresses and transferring or storing any amount smaller than this is not possiblelogo
: the official logo image of the tokenname
: name of the tokensymbol
: the 3 or 4-letter symbol of the token
With this, you’re all set to fetch token metadata using TokenAPI!
If you enjoyed this tutorial for getting address transaction history on Ethereum, give us a tweet @Alchemy! (Or if you have any questions/feedback give the author @ankg404 a shoutout!)
Don’t forget to join our Discord server to meet other blockchain devs, builders, and entrepreneurs!