πŸŽ‡Get the chain information for a Signer

Learn how to use ethers to query some basic EVM-network information

Check the network information using ethers.js

const { ethers } = require('ethers');

async function getNetworkInfo() {
  // Create a provider
  const provider = new ethers.providers.JsonRpcProvider(`https://moonbeam.unitedbloc.com`);

  // Get network information
  const network = await provider.getNetwork();

  console.log('Network Name:', network.name);
  console.log('Chain ID:', network.chainId);
  console.log('Block Explorer URL:', network.blockExplorer);
}

getNetworkInfo();

In this example, we use a Moonbeam provider. If you use a browser-injected provider, you'll receive the information about the current connected network.

Last updated