Ethers.js integration

Ethers.js is a lightweight JavaScript library for interacting with Ethereum and other EVM-compatible blockchains. It is commonly used by developers to build decentralized applications (dApps) and manage Ethereum-based operations like deploying smart contracts, interacting with them, and managing user wallets.

Install Ethers.js

Add Ethers.js to your project using your preferred package manager:

  • npm
bashnpm install ethers
  • yarn
bashyarn add ethers

Set GetBlock as a provider

javascript// Import the Ethers library
const { ethers } = require('ethers');

// Set up the provider (replace <region> and ACCESS_TOKEN with your actual values)
const provider = new ethers.JsonRpcProvider('https://shared.<region>.getblock.io/ACCESS_TOKEN');

//Call a method using the provider
const main = async () => {
  const blockNumber = await provider.getBlockNumber();
  console.log("Latest Block Number:", blockNumber);
};

// Call the main function
main();

For further details and advanced usage, explore the Ethers.js documentation.