Learn how to use Ethers.js to connect to a blockchain network through Node RPC.
Ethers.js is a standalone Typescript/Javascript for interacting with the Ethereum blockchain and its ecosystem.To connect to a network through Node RPC using Ethers 6 or 5, you can use the JSON-RPC provider backed by HTTPS or WebSockets.
Ethers 6
Ethers 5
ethers-6/json-rpc-provider.ts
// Installation Instructions: https://docs.ethers.io/v6/getting-startedimport { ethers } from "ethers";const RPC_URL = `https://mainnet.gateway.tenderly.co/${process.env.TENDERLY_NODE_ACCESS_KEY}`async function executeMethod() { // Initialize an ethers provider instance const provider = new ethers.JsonRpcProvider(RPC_URL); const blockNumber = await provider.getBlockNumber(); console.log(blockNumber);}await executeMethod();
ethers-5/json-rpc-provider.ts
// Installation Instructions: https://docs.ethers.io/v5/getting-startedimport { ethers } from "ethers";const RPC_URL = `https://mainnet.gateway.tenderly.co/${process.env.TENDERLY_NODE_ACCESS_KEY}`async function executeMethod() { // Initialize an ethers provider instance const provider = new ethers.providers.JsonRpcProvider(RPC_URL); const blockNumber = await provider.getBlockNumber(); console.log(blockNumber);}await executeMethod();