Authentication

To use the DeFi API, you must authenticate your requests using your API key. Here's how to do it.

1. Getting an API Key

To start using the DeFi API, you need an API key. If you don't have one, you can get one by contacting our sales team and registering for a DeFi API account.

Need a DeFI API key?

Interact with a variety of DeFi protocols across many Blockchains through a uniform and consistent API

2. Using Your API Key

Once you have your API key, you can authenticate your requests. Overall, three different methods exist to authenticate the DeFi API requests, depending on whether you have a new or legacy API key. Let's have a look at each below.

2.1. Using Your API Key as a Query Parameter

The easiest way to authenticate a Staking API endpoint request is via a query parameter:

  • parameter: apiKey
  • value: YOUR_API_KEY

At the end of any DeFi API endpoint, add the following: ?apiKey=YOUR_API_KEY. For example, to retrieve details of a stake by stake ID using our Staking API, use the following GET request:

https://svc.blockdaemon.com/defi/tokens?apiKey=YOUR_API_KEY

Authentication with a query parameter can be used with any tool - no additional actions are needed.

📘

Info:

Note that if the query has additional parameters, replace ? with &.

2.2. Using Your API Key as a Bearer Token

You can authenticate the Staking API requests by setting YOUR_API_KEY as a bearer token in the authorization header. Here are the instructions for doing this in cURL and Postman.

2.2.1. Bearer Token in cURL

When working with cURL, use the following code to set your YOUR_API_KEY as a bearer token:

--header 'Authorization: Bearer YOUR_API_KEY'

For example, to retrieve token details using our DeFi API, use the following code:

curl --request GET 'https://svc.blockdaemon.com/defi/tokens' \
--header 'Authorization: Bearer YOUR_API_KEY'

Or, if you prefer to use short options, run the following:

curl -X GET 'https://svc.blockdaemon.com/defi/tokens' \
-H 'Authorization: Bearer YOUR_API_KEY'

2.2.2. Bearer Token in Postman

In Postman, you can set YOUR_API_KEY as a bearer token for a particular request and a collection of requests. To do this, go to a request or collection tab and do the following:

  1. Navigate to the Authorization or Auth tab.
  2. Select Bearer Token from the Type drop-down menu.
  3. Paste your API key into the Token input box.

Then you can run your request.

3. Using Your API Key as an X-API-Key

You can authenticate the DeFi API requests by passing your YOUR_API_KEY in the X-API-Key header. Here are the instructions for doing this in cURL and Postman.

3.1. X-API-Key in cURL

When working with cURL, use the following code to set theYOUR_API_KEY as a bearer token:

--header 'X-API-Key: YOUR_API_KEY'

For example, to retrieve details of a stake using our Staking API, use the following code:

curl --request GET 'https://svc.blockdaemon.com/defi/tokens' \
--header 'X-API-KEY: YOUR_API_KEY'

Or, if you prefer to use short options, run the following:

curl -X GET 'https://svc.blockdaemon.com/defi/tokens' \
-H 'X-API-KEY: YOUR_API_KEY'

3.2. X-API-Key in Postman

In Postman, you can set YOUR_API_KEY as an X-API-Key not only for a particular request but also for a collection of requests. Go to a request or collection tab and do the following:

  1. Navigate to the Authorization or Auth tab.
  2. Select API Key from the Type drop-down menu.
  3. Paste your YOUR_API_KEY into the Value input box.
  4. Ensure the Add to option is set to Header.

Then you can run your request.

4. Getting the Result

If YOUR_API_KEY is correct, your request will be authorized, and you will get the result. For example, the requests from the sections above return token details grouped by chain id as requested:

{
  "tokens": {
    "1": [
      {
        "address": "0x0000000000000000000000000000000000000000",
        "chainID": "1",
        "chainType": "",
        "decimals": 18,
        "extensions": {
          "verified": true
        },
        "logoURI": "https://defi-images-blockdaemon-research-development-int-aa593eebdaa2fd.gitlab.io/tokens/1-0x0000000000000000000000000000000000000000.webp",
        "name": "Ether",
        "symbol": "ETH",
        "tags": [
          "native"
        ]
      },
      {
        "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
        "chainID": "1",
        "chainType": "",
        "decimals": 18,
        "extensions": {
          "bridgeInfo": {
            "10": {
              "tokenAddress": "0x4200000000000000000000000000000000000006"
            },
            "137": {
              "tokenAddress": "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619"
            },
            "42161": {
              "tokenAddress": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"
            },
            "42220": {
              "tokenAddress": "0x2DEf4285787d58a2f811AF24755A8150622f4361"
            },
            "43114": {
              "tokenAddress": "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB"
            },
            "56": {
              "tokenAddress": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8"
            },
            "8453": {
              "tokenAddress": "0x4200000000000000000000000000000000000006"
            },
            "84531": {
              "tokenAddress": "0x4200000000000000000000000000000000000006"
            }
          },
          "verified": true
        },
        "logoURI": "https://defi-images-blockdaemon-research-development-int-aa593eebdaa2fd.gitlab.io/tokens/1-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.webp",
        "name": "Wrapped Ether",
        "symbol": "WETH",
        "tags": []
      },
[...]

If the key is incorrect or missing, you will get this error:

{
  "type": "https://httpproblems.com/http-status/401",
  "title": "Unauthorized",
  "status": 401,
  "detail": "Authorization Failed",
  "instance": "/defi/tokens",
  "trace": {
    "timestamp": "2024-04-30T10:30:30.874Z",
    "requestId": "0b05fee3-b980-4655-a992-5c26f9192edd",
    "buildId": "61063bda-05ae-4030-af18-9db52377956e",
    "rayId": "87c6db5a6a7163b5"
  }
}

👋 Need Help?

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