25

How do you convert WEI to ETH? How do you convert WEI to ETH? How do you convert WEI to ETH?

Had to repost because it wouldn't let me post once.

user
  • 451
  • 1
  • 6
  • 11

2 Answers2

35

Take a look a formatEther in the ethers.js documentation

const weiValue = 100000;
const ethValue = ethers.utils.formatEther(weiValue);

You can also format an arbitrary amount of Wei into any other denomination using formatUnits.

const gweiValue = ethers.utils.formatUnits(weiValue, "gwei");
Codey
  • 451
  • 3
  • 3
2

To let it work fine with (e) format use that:

const balanceInWei = (+(await ethers.provider.getBalance(
  address
))).toLocaleString("fullwide", { useGrouping: false });

const balanceInEth= ethers.utils.formatEther(balanceInWei);

Ismael
  • 30,570
  • 21
  • 53
  • 96