Obtain Supported Chains and Tokens
This guide helps obtaining the chains the different portfolio view features support
The /chains
endpoint lists supported blockchains with their metadata, such as name and logo. This data can be used to present blockchain information to the user or for developers to leverage.
Obtaining Chains via cURL
Use the following curl
to retrieve supported chains:
curl --header "X-API-KEY: $YOUR_API_KEY" --request GET "https://svc.blockdaemon.com/defi/v1/chains?chainType=evm" | jq
The data for one chain will look like this:
[
{
"blockConfirmations": 12,
"blockExplorerUrls": [
"https://etherscan.io",
"https://eth.blockscout.com"
],
"blockTime": 20,
"chainID": "eip155:1",
"chainIconURI": "https://defi-images-blockdaemon-research-development-int-aa593eebdaa2fd.gitlab.io/chains/1.webp",
"chainName": "Ethereum",
"nativeCurrency": {
"decimals": 18,
"name": "Ether",
"symbol": "ETH"
},
"networkType": "mainnet",
"rpc": [
"https://eth.drpc.org",
"https://ethereum-rpc.publicnode.com",
"https://rpc.flashbots.net",
"https://svc.blockdaemon.com/ethereum/mainnet/native
]
},
[...]
You may find different pieces of data that allow managing portfolios. For instance, each chain shows its native currency, public and private RPC endpoints, logo, explorer, and information related to the finality of the chain.
Note:
- The chains endpoint provides multiple parameters to filter the returned Blockchains. In this example, we use
chainType=evm
to return only EVM chains. You may require a specific chain usingchainID=ID
, in CAIP-2 format. E.g., forOptimism
,chainID=eip155:10
. A complete API reference documentation can be found here.- This example uses the
jq
tool to format the response to make it easier to read. Feel free to omit it.
Obtaining Chains Programmatically
Our DeFi Examples repo contains example code for using the /chains
endpoint programmatically.
Let’s go through the relevant code sections step by step:
-
Make sure you have set your development environment as suggested.
-
We initialize the ChainsApi object with our configuration object, which includes the API key. Note that this configuration is done behind the scenes. The developer only needs to set up the
.env
file for configuration purposes. TheChainsApi
object can now interact programmatically with the/chains
endpoint.const api = new ChainsApi(apiConfig);
-
We configure the
GetChainsRequest
object, allowing us to request only the subset of blockchain metadata we are interested in. In this example, we only query Polygon Blockchains. Just leave the object empty to get all available metadata for all supported Blockchains. Please refer to the API specification at Chains for a list of all possible parameters.const chainsParameters: GetChainsRequest = {};
-
Finally, we query the API using the
ChainsApi
object together with the parameter object and log the returned data.const chains = await api.getChains(chainsParameters); log.info("Got chains"); log.info(chains);
-
To run the chains script, use the command:
npx ts-node src/main/scripts/get-chains.ts
Obtaining Chains for Portfolio Feature
The endpoint /chains
provides the chains that the API supports as a whole. Now, for the portfolio management guide, we want to know which chains each portfolio feature supports. The portfolio offers balances, approvals, and transaction features. Therefore, we will have one endpoint to fetch the supported chains for each of these features:
- Get chains for Balances:
curl --header "X-API-KEY: $YOUR_API_KEY" --request GET "https://svc.blockdaemon.com/defi/v1/balances/supported-chains" | jq
- Get chains for Approvals:
curl --header "X-API-KEY: $YOUR_API_KEY" --request GET "https://svc.blockdaemon.com/defi/v1/approvals/supported-chains" | jq
- Get chains for Transactions (🚧 WIP 🚧)
- Get chains for Exchange (🚧 WIP 🚧)
The response from the endpoints above contains less data than the/chains
endpoint, as it is an auxiliary endpoint. An example response:
[
{
"chainID": "eip155:1",
"chainName": "Ethereum",
"networkType": "mainnet",
},
{
"chainID": "eip155:56",
"chainName": "BSC",
"networkType": "mainnet",
},
Obtaining Tokens
The /tokens
endpoint lists supported tokens with their metadata, such as name, logo, price, etc., which can be used to present token information to the user. The token data follows the tokenlist
specification by Uniswap.
Obtaining Tokens via cURL
You may obtain a list of tokens with curl:
curl --header "X-API-Key: $YOUR_API_KEY" --request GET 'https://svc.blockdaemon.com/defi/v1/tokens' | jq
This command returns the full list of tokens BD supports. The response looks like the following:
{
"eip155:1": [
{
"address": "0x0000000000000000000000000000000000000000",
"chainID": "eip155:1",
"decimals": 18,
"extensions": {
"homepage": "https://ethereum.org/",
"verified": true
},
"logoURI": "https://defi-images-blockdaemon-research-development-int-aa593eebdaa2fd.gitlab.io/tokens/1-0x0000000000000000000000000000000000000000.webp",
"name": "Ether",
"priceUSD": 2711.38,
"symbol": "ETH",
"tags": [
"native",
"stargateV2"
]
},
{
"address": "0x0000000000085d4780b73119b644ae5ecd22b376",
"chainID": "eip155:1",
"decimals": 18,
"extensions": {
"homepage": "https://tusd.io/",
"verified": true
},
"logoURI": "https://defi-images-blockdaemon-research-development-int-aa593eebdaa2fd.gitlab.io/tokens/1-0x0000000000085d4780b73119b644ae5ecd22b376.webp",
"name": "TrueUSD",
"priceUSD": 0.998927,
"symbol": "TUSD",
"tags": [
"stablecoin"
]
},
[...]
Note that the first two tokens returned are native ETH on Ethereum and TUSD on Ethereum. Tags help identify and filter tokens. A full API reference for tokens can be found here.
You may also get tokens by chain and specific symbol:
curl --header "X-API-Key: $YOUR_API_KEY" --request GET 'https://svc.blockdaemon.com/defi/v1/tokens??tokenSymbol=USDC&chainID=eip155:10' | jq
The response will look like this:
{
"eip155:10": [
{
"address": "0x0000000000000000000000000000000000000000",
"chainID": "eip155:10",
"decimals": 18,
"extensions": {
"homepage": "https://www.optimism.io/",
"verified": true
},
"logoURI": "https://defi-images-blockdaemon-research-development-int-aa593eebdaa2fd.gitlab.io/tokens/10-0x0000000000000000000000000000000000000000.webp",
"name": "Ether (Optimism)",
"priceUSD": 1.056,
"symbol": "ETH",
"tags": [
"native",
"stargateV2"
]
},
[...]
Note the extensions
object: we are introducing a new extension to the specification, such that verified
signifies whether the Blockdaemon team has verified the token data. It’s up to the API consumer to verify the data for no-verified tokens.
Token Support:
If you require token data that hasn’t been verified or isn’t available at all, please reach out here.
Obtaining Tokens Programmatically
Our DeFi Examples repo contains example code for using the /tokens
endpoint programmatically. To run the script that obtains the available tokens, use the command: npm exec ts-node src/main/scripts/get-tokens.ts
Let’s go through the relevant code sections step by step:
- We initialize the object
TokensApi
with our configuration object. TheTokensApi
object can then be used to interact programmatically with the/tokens
endpoint.
const api = new TokensApi(apiConfig);
- We configure the
GetTokensRequest
object, which allows us to request only the subset of token data we are interested in. In this example, we only query USDC tokens. In the case of the cURL example of this guide, we further add the chain ID as Optimism (eip155:10). For a list of all possible parameters, please refer to the API specification at Tokens.
const tokensParameters: GetTokensRequest = {
tokenSymbol: "USDC",
chainID: "eip155:10",
};
- Finally, we query the API using the
TokensApi
object together with the parameter object and log the returned data.
const someTokens = await api.getTokens(tokensParameters);
log.info("Got USDC tokens");
log.info(JSON.stringify(someTokens, null, 2));
Filtering Tokens
Tokens can also be filtered by tags. To retrieve a list of all available tags, use the /tokens/tags endpoint
.
curl --header "X-API-Key: $YOUR_API_KEY" --request GET 'https://svc.blockdaemon.com/defi/v1/tokens/tags' | jq
You should see a response listing all available tags similar to this:
[
"native",
"stargatev2",
"stablecoin",
"defi",
"stargatev1",
"metaverse",
"wrapped-token",
"utility-token",
"gamefi",
"oracle",
"wallet",
"meme",
"bridge",
"exchange",
"staking",
"meme-token",
"nft-marketplace",
"axelar",
]
To filter the token list by a specific tag, use the tagLimit
parameter. For example, to fetch stablecoins:
curl --header "X-API-Key: $YOUR_API_KEY" --request GET 'https://svc.blockdaemon.com/defi/v1/tokens?tagLimit=stablecoin' | jq
To query with tags programmatically, use the filters as shown above.
const parameters = {
chainID: "eip155:1", // Fetch from Ethereum only
tagLimit: ["native", "stablecoin"] // Fetch native tokens only
}
👋 Need Help?
Contact us through email or our support page for any issues, bugs, or assistance you may need.
Updated 20 days ago