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
After you get your API key, you can use it to authenticate your requests. There are three methods to authenticate DeFi API requests. Here’s a quick overview of each.
2.1. Using Your API Key in a Query Parameter
To authenticate a DeFi API request, you can use your API key as a query parameter:
- parameter:
apiKey
- value:
YOUR_API_KEY
Add ?apiKey=YOUR_API_KEY
to the end of the DeFi API endpoint. For example, to get a list of tokens, use:
https://svc.blockdaemon.com/defi/tokens?apiKey=YOUR_API_KEY
You can use this method with any tool without needing extra steps.
Info:
If the URL already has other parameters, replace
?
with&
.
2.2. Using Your API Key in a Bearer Token
You can authenticate DeFi API requests by using YOUR_API_KEY
as a bearer token in the authorization header. Here’s how to do it in cURL and Postman.
2.2.1. Bearer Token in cURL
To set your API key as a bearer token in cURL, use this command:
--header 'Authorization: Bearer YOUR_API_KEY'
For example, to get token details, use:
curl --request GET 'https://svc.blockdaemon.com/defi/tokens' \
--header 'Authorization: Bearer YOUR_API_KEY'
Alternatively, with short options:
curl -X GET 'https://svc.blockdaemon.com/defi/tokens' \
-H 'Authorization: Bearer YOUR_API_KEY'
2.2.2. Bearer Token in Postman
To use your API key as a bearer token in Postman:
- Go to the Authorization or Auth tab.
- Select Bearer Token from the Type drop-down menu.
- Paste your API key into the Token field.
- Now you can run your request.
3. Using Your API Key as an X-API-Key
You can authenticate DeFi API requests by including your API key in the X-API-Key
header. Here’s how to do it in cURL and Postman.
3.1. X-API-Key in cURL
To set your API key as an X-API-Key
in cURL, use:
--header 'X-API-Key: YOUR_API_KEY'
For example, to get a list of tokens, use:
curl --request GET 'https://svc.blockdaemon.com/defi/tokens' \
--header 'X-API-KEY: YOUR_API_KEY'
Alternatively, with short options:
curl -X GET 'https://svc.blockdaemon.com/defi/tokens' \
-H 'X-API-KEY: YOUR_API_KEY'
3.2. X-API-Key in Postman
To use your API key as an X-API-Key
in Postman:
- Go to the Authorization or Auth tab.
- Select API Key from the Type drop-down menu.
- Paste your API key into the Value field.
- Ensure the Add to option is set to Header.
- Now you can run your request.
4. Getting the Result
Your request will be authorized if your API key is correct. For example, the request from the section above will return token details grouped by chain ID, as follows:
{
"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.