Connecting An Ethereum Shared Node Via JSON-RPC With Curl

Follow

Blockdaemon allows developers to read data from the Ethereum network and send transactions without having to host and manage a node themselves. You can do that by utilizing the existing the JSON-RPC API interface which a standard Blockdaemon node already implements.

To read data or send a transaction, you will send a POST request. The body of the POST will contain a JSON payload that contains the name of the JSON RPC method you wish to use and any additional parameters used by that method. For example, retrieving the current block number of the Ethereum network can be accomplished via this simple request:

 

curl -X POST --insecure -H "Content-Type: application/json" --data
'{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],
"id":64}' [http://[NODE IP]*

 

The result will look something like this: 

$ {"jsonrpc": "2.0","result": "0x657abc", "id":1}

 

*You can get your node URL + authorization token from the action>connect menu in your Blockdaemon node dashboard

eth_priv_connect_menu.jpg

The response will contain a JSON response payload which will be identical to what you would receive if running a local node. This allows developers to easily swap between our remote service and a local node.

Curl is commonly used to send JSON-RPC requests. We will be using curl in the following example but any tool that can send HTTP(s) requests can be used instead. For an example on how to use JSON-RPC programmatically, please see our article about using JSON-RPC via web3py.

On many systems curl is already installed out-of-the-box but if it’s not it can be installed on Linux, Windows, and OSX  

We don’t allow all RPC methods because some are not suitable in a multi-user (shared) environment.

Useful links

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.