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 to make the HTTPS requests and for WebSocket requests.
Ensure that you replaceYOUR-API-KEY with a API key from your chainRPC dashboard.
Click the Run in Postman button below to fork the collection and make requests.
Web3.js
Save the following script to a file, e.g. index.js
var Web3 = require('web3');
var provider = 'https://eth.chainrpc.io/v3/<API-KEY>';
var web3Provider = new Web3.providers.HttpProvider(provider);
var web3 = new Web3(web3Provider);
web3.eth.getBlockNumber().then((result) => {
console.log("Latest Ethereum Block is ",result);
});
In a terminal window, run the script with node index.js
Latest Ethereum Block is 14659509
Ethers
Save the following script to a file, e.g. index.js
var ethers = require('ethers');
var url = 'https://eth.chainrpc.io/v3/<API-KEY>';
var customHttpProvider = new ethers.providers.JsonRpcProvider(url);
customHttpProvider.getBlockNumber().then((result) => {
console.log("Current block number: " + result);
});
In a terminal window, run the script with node index.js
Latest Ethereum Block is 14659509
NodeJS
Save the following script to a file, e.g. index.js