Blockdaemon Documentation
Authentication
Overview
Generating a Ubiquity API Key
Using New vs. Legacy API Keys
Using API Key as a Query Parameter
Using API Key as a Bearer Token
Using API Key as an X-API-Key
Getting the Result
Overview
This article explains how generate a Ubiquity API key and use it to authenticate Ubiquity API requests.
You can pass the key either as a query parameter or as a bearer token in the authorization header. Below you will find examples showing how to set the bearer token in cURL and Postman.
Generating a Ubiquity API Key
To use the Ubiquity blockchain API, you need to get the API access key. This is a 47-character unique number.
To generate a Ubiquity API key, sign up to the Blockdaemon application and take the following steps:
- Navigate to Ubiquity API > Connect > API Keys
- Click on Create API Key
- In the pop-up window, enter your desired Key Name
- Click on the Create API Key button to generate the key
- Click on your key to copy it
Check out our video guide on creating your Ubiquity API Key
Please note:
- If you lose the key, you will not be able to retrieve it
- You should immediately store your key in a secure place
Using New vs. Legacy API Keys
For new API keys, the following authorization methods are available:
You should use this base URL for your requests:
https://svc.blockdaemon.com
If you created your Ubiquity API Key before September 2022, use the following authorization methods:
The base URL for legacy API keys is the following:
https://ubiquity.api.blockdaemon.com
Using API Key as a Query Parameter
The easiest way to authenticate a Ubiquity request is via a special query parameter:
- parameter:
apiKey
- value: your API key
At the end of any Ubiquity endpoint, just add the following: ?apiKey=YOUR_API_KEY
For example, to authorize a request for getting the current block number in Ethereum Mainnet, use the following code:
https://svc.blockdaemon.com/universal/v1/ethereum/mainnet/sync/block_number?apiKey=YOUR_API_KEY
Notes:
- If the query has other parameters, replace
?
with&
- This authentication method can be used with any tool, no additional actions needed
Using API Key as a Bearer Token
You can authenticate Ubiquity API requests by setting your API key as a bearer token in the authorization header. Below you will find examples showing how to do it when using cURL and Postman.
Bearer Token in cURL
When working with cURL, use the following code to set your API key as a bearer token:
--header 'Authorization: Bearer YOUR_API_KEY'
For example, to get the current block number in Ethereum Mainnet, run this code:
curl --request GET 'https://svc.blockdaemon.com/universal/v1/ethereum/mainnet/sync/block_number' --header 'Authorization: Bearer YOUR_API_KEY'
If you prefer to use short options, run the following:
curl -X GET 'https://svc.blockdaemon.com/universal/v1/ethereum/mainnet/sync/block_number' -H 'Authorization: Bearer YOUR_API_KEY'
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.
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. For example, to get the current block number in Ethereum Mainnet, use the following:
https://svc.blockdaemon.com/universal/v1/ethereum/mainnet/sync/block_number
Using API Key as an X-API-Key
You can authenticate Ubiquity API requests by passing your API key in the X-API-Key header. Below you will find examples showing how to do it when using cURL and Postman.
X-API-Key in cURL
When working with cURL, use the following code to set your API key as a bearer token:
--header 'Authorization: X-API-Key YOUR_API_KEY'
For example, to get the current block number in Ethereum Mainnet, run this code:
curl --request GET 'https://svc.blockdaemon.com/universal/v1/ethereum/mainnet/sync/block_number' --header 'X-API-Key: YOUR_API_KEY'
If you prefer to use short options, run the following:
curl -X GET 'https://svc.blockdaemon.com/universal/v1/ethereum/mainnet/sync/block_number' -H 'X-API-Key: YOUR_API_KEY'
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 API key into the Value input box
- Make sure that the Add to option is set to Header
Then you can run your request. For example, to get the current block number in Ethereum Mainnet, use the following:
https://svc.blockdaemon.com/universal/v1/ethereum/mainnet/sync/block_number
Getting the Result
If the API key is correct, your request will be authorized, and you will get the result.
The requests from the sections above return the current block number in Ethereum Mainnet, for example:
14589247
If the key is incorrect or missing, you will get the following error:
{
"status": 401,
"type": "unauthorized",
"title": "Invalid Token"
}