Learn how easy it is to authenticate requests with the Blockdaemon RPC API.
To use the Blockdaemon RPC API, you need to authenticate your requests with your Blockdeamon API Suite API key. Here's how to do it.
1. Getting an API Key
To start using the Blockdaemon RPC API, you need to get an API key. If you don't have one, you can get a free one by signing up for Blockdaemon. Once you have an API key, you can authenticate your requests.
Need a Free API key?
Enjoy Rapid, Scalable, Multi-Protocol Blockchain Access with Ubiquity.
2. Using Your API Key
Once you have your API key, you can authenticate your requests. Overall, there are three different methods to authenticate the requests, depending on whether you have a new or legacy API key.
2.1. Using Your API Key as a Query Parameter
The easiest way to authenticate a Blockdeamon API Suite request is via a special query parameter:
- parameter:
apiKey
- value:
YOUR_API_KEY
At the end of any Blockdeamon API Suite endpoint, add the following: ?apiKey=YOUR_API_KEY
. See the following cases:
Ethereum Mainnet
https://svc.blockdaemon.com/ethereum/mainnet/native?apiKey=YOUR_API_KEY
HTTP RPC (e.g., Osmosis, Fantom, Base)
https://svc.blockdaemon.com/optimism/mainnet/native/http-rpc?apiKey=YOUR_API_KEY
Tendermint REST (e.g., Polygon, Cronos, Cosmos)
https://svc.blockdaemon.com/polygon/mainnet/native/tendermint-rest/YOUR_METHOD?apiKey=YOUR_API_KEY
Tendermint RPC (e.g., Polygon, Cronos, Cosmos)
https://svc.blockdaemon.com/cronos/mainnet/native/tendermint-rpc?apiKey=YOUR_API_KEY
Info:
Authentication with a query parameter can be used with any tool - no additional actions are needed.
2.2. Using Your API Key as a Bearer Token
You can authenticate Blockdeamon API Suite API requests by setting YOUR_API_KEY
as a bearer token in the authorization header.
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 the current block number in Ethereum Mainnet, use the following request: :
curl --request POST 'https://svc.blockdaemon.com/ethereum/mainnet/native' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_blockNumber",
"params": []
}
Or, if you prefer to use short options, run the following:
curl -X POST 'https://svc.blockdaemon.com/ethereum/mainnet/native' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_blockNumber",
"params": []
}
2.2.2. Bearer Token in Postman
In Postman, you can set YOUR_API_KEY
as a bearer token not only for a particular request but also for a collection of requests. To do this, go to a request or collection tab and do the following:
- Navigate to the Authorization or Auth tab.
- Select Bearer Token from the Type drop-down menu.
- Paste
YOUR_API_KEY
into the Token input box.
Then you can run your request.
2.3. Using Your API Key as an X-API-Key
You can authenticate Blockdeamon API Suite requests by passing your YOUR_API_KEY
in the X-API-Key
header.
2.3.1. X-API-Key in cURL
When working with cURL, use the following code to set YOUR_API_KEY
as a bearer token:
--header 'X-API-Key: YOUR_API_KEY'
For example, to retrieve the current block number in Ethereum Mainnet, use the following request: :
curl --request POST 'https://svc.blockdaemon.com/ethereum/mainnet/native' \
--header 'X-API-Key: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_blockNumber",
"params": []
}'
Or, if you prefer to use short options, run the following:
curl -X POST 'https://svc.blockdaemon.com/ethereum/mainnet/native' \
-H 'X-API-Key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_blockNumber",
"params": []
}
2.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:
- Navigate to the Authorization or Auth tab.
- Select API Key from the Type drop-down menu.
- Paste your
YOUR_API_KEY
into the Value input box. - Ensure the Add to option is set to Header.
Then you can run your request.
3. Getting the Result
If YOUR_API_KEY
is correct, your request will be authorized, and you will get the result. For example, the requests above will give you the current block number in Ethereum Mainnet if authorized:
{
"jsonrpc": "2.0",
"id": 1,
"result": "0xe9c344"
}
If the key is incorrect or missing, you will get this error:
{
"status": 401,
"type": "unauthorized",
"title": "Invalid Token"
}
👋 Need Help?
Contact us through email or our support page for any issues, bugs, or assistance you may need.