Get Supported Tokens and Their Metadata

Overview

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.

curl  --header 'X-API-Key: <YOUR API KEY> 'https://svc.blockdaemon.com/defi/tokens??tokenSymbol=USDC&chainID=10' | jq

❗️

Note:

  • The chains endpoint provides multiple parameters to filter the returned Blockchains. In this example we use ?tokenSymbol=USDC&chainID=10 to return only USDC on Optimism. 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:

{  
  "tokens": {  
    "10": [  
      {  
        "address": "0x0b2c639c533813f4aa9d7837caf62653d097ff85",  
        "chainID": "10",  
        "chainType": "evm",  
        "decimals": 6,  
        "extensions": {  
          "bridgeInfo": {  
            "1": {  
              "tokenAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"  
            }  
          },  
          "verified": true  
        },  
        "logoURI": "<https://defi-images-blockdaemon-research-development-int-aa593eebdaa2fd.gitlab.io/tokens/10-0x0b2c639c533813f4aa9d7837caf62653d097ff85.webp">,  
        "name": "USDCoin",  
        "symbol": "USDC",  
        "tags": [  
          "stablecoin"  
        ]  
      }  
    ]  
  }  
}

API Usage Notes

  • In most user interfaces a user needs to select a Blockchain before selecting a token support on the Blockchain. To facilitate this use case, the Tokens API returns tokens grouped by chainId.
  • The token data follows the tokenlist specification by Uniswap.
  • We’re introducing a new extension to the specification. verified signifies whether the token data has been verified by the Blockdaemon team. It’s up to the consumer of the API to verify the data for non verified tokens.

📘

Info:

If you require token data that hasn’t been verified or isn’t available at all, please reach out here.


Code Example

https://github.com/Blockdaemon/defi-api-examples/blob/main/src/main/scripts/get-tokens.ts contains example code for using the /tokens 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-tokens.ts

Let’s go through the relevant code sections step by step:

  1. We initialise the object TokensApi with our configuration object (see: Set Up the Development Environment) which includes the API key. The TokensApi object can then be used to interact programmatically with the /tokens endpoint.

    const api = new TokensApi(apiConfig);
    
  2. We configure the GetTokensRequest object which allows us to request only the subset of token data we are interested in. In this example we query only USDC tokens. To get data for all supported tokens, just leave the object empty. For a list of all possible parameters, please refer to the API specification at Tokens.

    const tokensParameters: GetTokensRequest = {
      tokenSymbol: "USDC",
    };
    
  3. Finally we query the API using the TokensApi object together with the 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));
    

👋 Need Help?

Contact us through email or our support page for any issues, bugs, or assistance you may need.