alchemy_getTokenMetadata
Returns metadata (name, symbol, decimals, logo) for a given token contract address.
name ,symbolanddecimalsare optional methods in the ERC-20 token standard. Therefore, not all contracts will respond correctly to calls requesting this information. While the incorrectness or absence ofname and symbolcan be an inconvenience, having the correct decimalsis absolutely crucial in displaying token balances or converting user inputs accurately when communicating with the contract.
Alchemy maintains a regularly updated database of contract metadata, with values gathered and intelligently merged from the contracts themselves along with several other sources. Alchemy is therefore able to provide clean, accurate, up-to-date metadata for contracts that may be missing any of these methods or have changed their name or symbol since contract publication.
As a bonus, token logo images are available for many of the popular tokens.

Parameters

  1. 1.
    DATA, 20 Bytes - The address of the token contract.

Returns

Object - An object with the following fields:
  • 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

Alchemy Web3
Fetch (JS)
Axios (JS)
Curl
Postman
1
// alchemy-token-api/alchemy-web3-script.js
2
import { createAlchemyWeb3 } from "@alch/alchemy-web3";
3
4
// Replace with your Alchemy api key:
5
const apiKey = "demo";
6
7
// Initialize an alchemy-web3 instance:
8
const web3 = createAlchemyWeb3(
9
`https://eth-mainnet.g.alchemy.com/v2/${apiKey}`,
10
);
11
12
// The token address we want to query for metadata:
13
const metadata = await web3.alchemy.getTokenMetadata("0x1985365e9f78359a9B6AD760e32412f4a445E862")
14
15
console.log("TOKEN METADATA->");
16
console.log(metadata);
Copied!
1
import fetch from 'node-fetch';
2
3
// Replace with your Alchemy API key:
4
const apiKey = "demo";
5
const fetchURL = `https://eth-mainnet.g.alchemy.com/v2/${apiKey}`;
6
7
// Replace with the token address you want to query:
8
const tokenAddr = "0x1985365e9f78359a9B6AD760e32412f4a445E862";
9
10
var raw = JSON.stringify({
11
"jsonrpc": "2.0",
12
"method": "alchemy_getTokenMetadata",
13
"headers": {
14
"Content-Type": "application/json"
15
},
16
"params": [
17
`${tokenAddr}`
18
],
19
"id": 42
20
});
21
22
var requestOptions = {
23
method: 'POST',
24
body: raw,
25
redirect: 'follow'
26
};
27
28
// Make the request and print the formatted response:
29
fetch(fetchURL, requestOptions)
30
.then(response => response.json())
31
.then(response => JSON.stringify(response, null, 2))
32
.then(result => console.log(result))
33
.catch(error => console.log('error', error));
Copied!
1
// alchemy-token-api/axios-script.js
2
import axios from 'axios';
3
4
// Replace with your Alchemy API key:
5
const apiKey = "demo";
6
const baseURL = `https://eth-mainnet.g.alchemy.com/v2/${apiKey}`;
7
// Replace with the wallet address you want to query:
8
const tokenAddr = "0x1985365e9f78359a9B6AD760e32412f4a445E862";
9
10
var data = JSON.stringify({
11
"jsonrpc": "2.0",
12
"method": "alchemy_getTokenMetadata",
13
"params": [
14
`${tokenAddr}`
15
],
16
"id": 42
17
});
18
19
var config = {
20
method: 'post',
21
url: baseURL,
22
headers: {
23
'Content-Type': 'application/json'
24
},
25
data : data
26
};
27
28
axios(config)
29
.then(function (response) {
30
console.log(JSON.stringify(response.data, null, 2))
31
})
32
.catch(function (error) {
33
console.log(error);
34
});va
Copied!
1
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
2
-X POST \
3
-H "Content-Type: application/json" \
4
-d '{"jsonrpc":"2.0","method":"alchemy_getTokenMetadata","params": ["0x1985365e9f78359a9B6AD760e32412f4a445E862"], "id": 1}'
Copied!
1
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
2
RequestType: POST
3
Body:
4
{
5
"jsonrpc":"2.0",
6
"method":"alchemy_getTokenMetadata",
7
"params":["0x1985365e9f78359a9B6AD760e32412f4a445E862"],
8
"id":1
9
}
Copied!

Result

1
{
2
"jsonrpc": "2.0",
3
"id": 1,
4
"result": {
5
"logo": "https://static.alchemyapi.io/images/assets/1104.png",
6
"symbol": "REP",
7
"decimals": 18,
8
"name": "Augur"
9
}
10
}
Copied!