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.
Ensure that you replaceYOUR-API-KEY with a API key from your chainRPC dashboard.
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);
});
Latest Ethereum Block is 14659509
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);
});