RPC via GetBlock
GetBlock is a provider of access to full nodes of the most popular cryptocurrencies:
- Instant connection to blockchain nodes of 45+ cryptocurrencies including RSK, Bitcoin (BTC), Ethereum (ETH), among others
- Supports JSON-RPC, REST and Websocket APIs
- Free plan — up to 40K requests/day
In this tutorial, you will learn how to connect to an RSK node using different endpoints or API methods available within GetBlock.
How to make a JSON-RPC request over HTTP
Mainnet
To send JSON RPC over HTTP, it is required to send the request using POST to URL rsk.getblock.io/mainnet
with the headers Content-Type:application/json
and x-api-key:your-api-key
, and also, the request body.
The example of receiving the number of the last block:
{"jsonrpc": "2.0","id": "healthcheck","method": "eth_getBlockByNumber","params": ["latest", false]}
Here's the full code sample:
- Linux, Mac OSX
curl --location --request POST 'https://rsk.getblock.io/mainnet/' \ --header 'x-api-key:<YOUR-API-KEY>' \ --header 'Content-Type: application/json' \ --data-raw '{ "id": "blockNumber", "jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params": ["latest", false]}'
- Windows
curl --location --request POST 'https://rsk.getblock.io/mainnet/' \ --header 'x-api-key:<YOUR-API-KEY>' \ --header 'Content-Type: application/json' \ --data-raw '{ "id": "blockNumber", "jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params": ["latest", false]}' }'
Result
{"jsonrpc":"2.0","id":"blockNumber","result":{"number":"0x3bfe8d","hash":"0xa431674a114cbfa4ed94748e114c87430e2d4dc325e34e52688bbcbdc1eabd9b"......
Testnet
To send JSON RPC over HTTP, it is required to send the request using POST to the testnet URL rsk.getblock.io/testnet
with the headers Content-Type:application/json
and x-api-key:your-api-key
, and also, the request body.
The example of receiving the number of the last block:
{"jsonrpc": "2.0","id": "healthcheck","method": "eth_getBlockByNumber","params": ["latest", false]}
Here's the full code sample:
- Linux, Mac OSX
curl --location --request POST 'https://rsk.getblock.io/testnet/' \ --header 'x-api-key:<YOUR-API-KEY>' \ --header 'Content-Type: application/json' \ --data-raw '{ "id": "blockNumber", "jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params": ["latest", false]}'
- Windows
curl --location --request POST 'https://rsk.getblock.io/testnet/' \ --header 'x-api-key:<YOUR-API-KEY>' \ --header 'Content-Type: application/json' \ --data-raw '{ "id": "blockNumber", "jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params": ["latest", false]}'
Result
{"jsonrpc":"2.0","id":"blockNumber","result":{"number":"0x250256","hash":"0x7c010a2b60622981c0ba90b6354131698b87e54cfa8fe21ee9616d64b715eed8".......,
How to make a JSON-RPC request using Postman
Visit: Postman Collection
Websockets
To send JSON RPC over WebSockets, it is required to establish the connection:
Mainnet
- Linux, Mac OSX
wscat -c wss://rsk.getblock.io/mainnet/websocket -H "x-api-key:<YOUR-API-KEY>”
- Windows
wscat -c wss://rsk.getblock.io/mainnet/websocket -H "x-api-key:<YOUR-API-KEY>”
Then, send the request body:
{"jsonrpc": "2.0","id": "healthcheck","method": "eth_getBlockByNumber","params": ["latest", false]}
Testnet
- Linux, Mac OSX
wscat -c wss://rsk.getblock.io/testnet/websocket -H "x-api-key:<YOUR-API-KEY>”
- Windows
wscat -c wss://rsk.getblock.io/testnet/websocket -H "x-api-key:<YOUR-API-KEY>”
Then, send the request body:
{"jsonrpc": "2.0","id": "healthcheck","method": "eth_getBlockByNumber","params": ["latest", false]}
Result
# > {"jsonrpc": "2.0","id": "healthcheck","method": "eth_getBlockByNumber","params": ["latest", false]}
# < {"jsonrpc":"2.0","id":"healthcheck","result":{"number":"0x3bfee3","hash":"0xb8a48a6df1fe24be6473177d5259df81e60a40bafee174b7ed37274c57d5ced3","parentHash":"0xdd07746cc68e303ff5d567ae1d19e7732bb9f8a02c8d6d71db5312337fe265c9",