The API uses API keys for authentication. First, you need to get an API key.
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. You can also sign up on our platform .
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.2. As 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/v1/tokens?apiKey=YOUR_API_KEY
You can use this method with any tool without needing extra steps. Note that if the URL already has other parameters, replace ?
with &
.
2.2. As a Bearer Token
You can authenticate DeFi API requests by using YOUR_API_KEY
as a bearer token in the authorization header.
- 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/v1/tokens' \
--header 'Authorization: Bearer YOUR_API_KEY'
- Alternatively, with short options:
curl -X GET 'https://svc.blockdaemon.com/defi/v1/tokens' \
-H 'Authorization: Bearer YOUR_API_KEY'
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.
--header 'X-API-Key: YOUR_API_KEY'
- For example, to get a list of tokens, use:
curl --request GET 'https://svc.blockdaemon.com/defi/v1/tokens' \
--header 'X-API-KEY: YOUR_API_KEY'
- Alternatively, with short options:
curl -X GET 'https://svc.blockdaemon.com/defi/v1/tokens' \
-H 'X-API-KEY: YOUR_API_KEY'
4. Verifying Your API Key
Let's verify your API key by making a request to the /chains
endpoint:
curl --header "X-API-KEY: $YOUR_API_KEY" --request GET "https://svc.blockdaemon.com/defi/v1/chains" | jq
A successful request will return details about supported blockchains. For example:
[
{
"blockConfirmations": 6,
"blockExplorerUrls": [
"https://optimistic.etherscan.io",
"https://optimism.blockscout.com"
],
"blockTime": 2,
"chainID": "eip155:10",
"chainIconURI": "https://defi-images-blockdaemon-research-development-int-aa593eebdaa2fd.gitlab.io/chains/10.webp",
"chainName": "Optimism",
"nativeCurrency": {
"decimals": 18,
"symbol": "ETH"
},
"networkType": "mainnet"
}
]
If your API key is invalid or missing, you'll receive an error response:
{
"type": "https://httpproblems.com/http-status/401",
"title": "Unauthorized",
"status": 401,
"detail": "Authorization Failed",
"instance": "/defi/chains",
"trace": {
"timestamp": "2024-04-30T10:30:30.874Z",
"requestId": "0b05fee3-b980-4655-a992-5c26f9192edd"
}
}
👋 Need Help?
Contact us through email or our support page for any issues, bugs, or assistance you may need.