Returns metadata for a given token contract address.
Don’t have an API key?
Start using this method in your app today.
Description
Returns metadata for a given token contract address.
Parameters
Name | Type | Description |
---|---|---|
address | string | The contract address to get metadata for. |
Response
Parameters | Type | Description |
---|---|---|
Promise<TokenMetadataResponse> | object | Returns metadata for a given token contract address |
TokenMetadataResponse
object parameters
TokenMetadataResponse
object parametersProperty | Type | Description |
---|---|---|
name | string | The token's name, null if not defined in the contract and not available from other sources. |
symbol | string | The token's symbol. null if not defined in the contract and not available from other sources. |
decimals | number | The number of decimals of the token. null if not defined in the contract and not available from other sources. |
logo | string | URL of the token's logo image. null if not available. |
Example Request and Response
Prerequisite: You will need to install the Alchemy SDK before making requests with it.
The commands for installing it using npm or yarn are given below:
npm install alchemy-sdk
yarn add alchemy-sdk
Request
Here is an example of how to make a getTokenMetadata
request using the Alchemy SDK:
// Imports the Alchemy SDK
const { Alchemy, Network } = require("alchemy-sdk");
// Configures the Alchemy SDK
const config = {
apiKey: "alchemy-replit", // Replace with your API key
network: Network.ETH_MAINNET, // Replace with your network
};
// Creates an Alchemy object instance with the config to use for making requests
const alchemy = new Alchemy(config);
const main = async () => {
//Initialize variables for the parameters
const usdcContract = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
//Call the method to retrieve the token metadata
let response = await alchemy.core.getTokenMetadata(usdcContract)
//Logging the response to the console
console.log(response)
};
main();
Response
{
decimals: 6,
logo: 'https://static.alchemyapi.io/images/assets/3408.png',
name: 'USD Coin',
symbol: 'USDC'
}
Code Sandbox
You can test out the getTokenMetadata
method using the code sandbox below:
Use Cases
Here are some possible use cases for the getTokenMetadata
method:
- Displaying Token Information: DApps and other blockchain applications often need to display information about a particular token. By using
getTokenMetadata
, developers can easily retrieve information such as the token name, symbol, and decimal places for display in their application.
Related Methods
Here are the methods related to getTokenMetadata
:
- getTokenBalances: Returns the ERC-20 token balances for a specific owner address.
- getFeeData: Returns the recommended fee data to use in a transaction. For an EIP-1559 transaction, the
maxFeePerGas
andmaxPriorityFeePerGas
should be used.