⚡ We welcome businesses to test our enterprise-grade service

/

Authentication with API Key

# Authentication with API Key

Once you created an account and signed in, you will be taken to the GetBlock Dashboard. There you will find an automatically generated API key – a token required for the interaction with the service and making API requests.

screenshot 1

You can create several API keys if needed. Simply press the “Create new API Key” link in the block located next to your API key.

screenshot 2

Enter the name for a new API key and press the “Create” button in the pop-up window.

screenshot 3

The new API key will be displayed next to the previous one.

screenshot 4

The received API keys are required for sending requests to our blockchain nodes. Your requests can’t be processed without the API key, you will receive the 400 Bad Request error with the response body “Apikey missed”.

You can authenticate with the API key using two methods:

Recommended method.

Copy the API key from the Dashboard and paste it to the x-api-key request header:

Host:<SYMBOL>.getblock.io/mainnet/
x-api-key:YOUR-API-KEY

The API key can be also sent in the query string:

https://<SYMBOL>.getblock.io/mainnet/?api_key=YOUR-API-KEY

Each node has its own set of methods for interaction with the blockchain network. You can find methods for several nodes in the Available Nodes Methods tab in Documentation.

If you can’t find methods for the node you need, you can always find them in the Nodes Endpoints section by clicking the required API interface (JSON-RPC, REST or WS) button located next to the endpoint of the node.

screenshot 5

How to send requests to a node (ex. Ethereum and Bitcoin)

The Ethereum node supports JSON-RPC and WebSockets interfaces, while the Bitcoin node – REST and JSON-RPC. You can access the connection using such command-line utilities as cURL and wscat, and also various libraries built for interaction with certain blockchains. The guides on how to connect to GetBlock with Web3.js , TronWeb and MetaMask are provided in Documentation.

Wscat

If you want to send data requests with WebSockets, you can use several libraries or wscat. You can install and use wscat as follows:

• Download wscat from https://www.npmjs.com/package/wscat

• Install wscat by running the following command: npm install -g wscat

You can connect to the Ethereum node with wscat using two options:

1. Recommended.
wscat -c 'wss://eth.getblock.io/mainnet/' --header 'x-api-key: <Api key>' 2. wscat -c 'wss://eth.getblock.io/mainnet/?api_key=<Api key>'

When the command is performed, you will get a response inside the terminal that the connection is successfully enabled.

screenshot 6

Then, you can send the following request:

{"jsonrpc": "2.0", "method": "eth_getBlockByNumber",
"params": ["latest", false], "id": "getblock.io"}
screenshot 7

cURL

The cURL command is accessible on all Linux based distributions by default. cURL is commonly used to send JSON-RPC and REST requests. Here is an example of how to send a JSON-RPC request to the Ethereum node:

curl --location --request POST "https://eth.getblock.io/mainnet/"
--header "x-api-key: < Api key >"
--header 'Content-Type: application/json'
--data-raw '{ "jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params": ["latest", false], "id": "getblock.io" }'

Here is the response you will receive back to retrieve the latest block number:

screenshot 8

The process of sending REST requests is quite similar. Here is an example of how to send a REST request to the Bitcoin node:

curl --location --request GET 'https://btc.getblock.io/rest/
chaininfo.json'
--header 'x-api-key: <Api key>'
screenshot 9

Postman

The Postman collection of requests can be found in our documentation:

https://getblock.io/docs/get-started/postman-collection/