How to get Ether balance in ethers v6

How to get Ether balance in ethers v6

314

Here is sample code of how to check ether balance using NodeJS,

// ether.js version 6
import { ethers } from 'ethers';

const provider = new ethers.getDefaultProvider("goerli");  // use goerli testnet
await provider.getBalance('0x48......f2').then((balance) => {
    // convert a currency unit from wei to ether
    const balanceInEth = ethers.formatEther(balance)
    console.log(`balance: ${balanceInEth} ETH`);
});

Notes:

  1. Replace goerli with your network.
  2. Replace 0x48......f2 with your wallet hex.

That's it. Now you can see your wallet balance.

- Last updated 9 months ago

Ads

Be the first to leave a comment.

You must login to leave a comment