Make requests

The Ethereum network supports requests with HTTP or WebSockets. HTTP requires continual requests to the URL endpoint, whereas WebSockets maintains the connection. You can also make batch requests to the Ethereum network.

curl or wscat

Use curl to make the HTTPS requests and wscat for WebSocket requests.

curl -X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber", "params": []}' \
"https://eth.chainrpc.io/v3/YOUR-API-KEY"

Postman

Call the JSON-RPC methods using Postman.

Click the Run in Postman button below to fork the collection and make requests.

Set the correct variables for your API key and network before running requests.

Ethereum API Postman collection

Web3.js

Save the following script to a file, e.g. index.js

In a terminal window, run the script with node index.js

Ethers

Save the following script to a file, e.g. index.js

In a terminal window, run the script with node index.js

NodeJS

Save the following script to a file, e.g. index.js

In a terminal window, run the script with node index.js

Go

  1. Initialize a new go module: go mod init infura.

  2. Install the go-ethereum dependency: go get github.com/ethereum/go-ethereum/rpc.

  3. Save the following script to a file, e.g. infura.go.

In a terminal window, run the script with go run infura.go.

Output:

Python

Run the following code with Python.

Output looks like:

Last updated