Get Supported Blockchains and Their Metadata
Overview
The /chains
endpoint lists supported Blockchains with their metadata, such as name, logo, etc., which can be used to present Blockchain information to the user.
Let’s first use curl
to familiarize ourselves with the data:
curl --header 'X-API-Key:YOUR_API_KEY' "https://svc.blockdaemon.com/defi/chains?chainType=evm" | jq
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 by usingchainID=ID
. E.g., forOptimism
,chainID=eip155:10
. A full API reference documentation can be found here.- This example use the
jq
tool to format the response to make it easier to read. Feel free to omit it.
The response will look like this:
[
{
"blockConfirmations": 12,
"blockExplorerUrls": [
"https://etherscan.io",
"https://eth.blockscout.com"
],
"blockTime": 20,
"chainID": "1",
"chainIconURI": "https://defi-images-blockdaemon-research-development-int-aa593eebdaa2fd.gitlab.io/chains/1.webp",
"chainName": "Ethereum",
"chainType": "evm",
"nativeCurrency": {
"decimals": 18,
"name": "Ether",
"symbol": "ETH"
},
"networkType": "mainnet",
"rpc": [
"https://eth.drpc.org",
"wss://eth.drpc.org"
]
},
{
"blockConfirmations": 6,
"blockExplorerUrls": [
"https://optimistic.etherscan.io",
"https://optimism.blockscout.com"
],
"blockTime": 2,
"chainID": "10",
"chainIconURI": "https://defi-images-blockdaemon-research-development-int-aa593eebdaa2fd.gitlab.io/chains/10.webp",
"chainName": "Optimism",
"chainType": "evm",
"nativeCurrency": {
"decimals": 18,
"name": "Ether",
"symbol": "ETH"
},
"networkType": "mainnet",
"rpc": [
"https://optimism.drpc.org",
"wss://optimism.drpc.org"
]
},
[...]
Code Example
https://github.com/Blockdaemon/defi-api-examples/blob/main/src/main/scripts/get-chains.ts contains example code for using the /chains
endpoint programmatically.
Please refer to Set Up the Development Environment for the basic setup of the project. To run the script use the command: npx ts-node src/main/scripts/get-chains.ts
Let’s go through the relevant code sections step by step:
-
We initialise the object
ChainsApi
with our configuration object (see: Set Up the Development Environment) which includes the API key. TheChainsApi
object can then be used to interact programmatically with the/chains
endpoint.const api = new ChainsApi(apiConfig);
-
We configure the
GetChainsRequest
object which allows us to request only the subset of Blockchain metadata we are interested in. In this example we query only Polygon Blockchains. To get all available metadata for all supported Blockchains, just leave the object empty. For a list of all possible parameters, please refer to the API specification at Chains.const chainsParameters: GetChainsRequest = {};
-
Finally we query the API using the
ChainsApi
object together with the the parameter object and log the returned data.const chains = await api.getChains(chainsParameters); log.info("Got chains"); log.info(chains);
👋 Need Help?
Contact us through email or our support page for any issues, bugs, or assistance you may need.
Updated about 2 months ago