Skill 1.2.1
Convert between wei, gwei and ether and handle BigInt values
Key Concepts
The smallest unit of ether is the wei. One gwei is 109 wei and is the usual unit for gas prices; one ether is 1018 wei. Nodes, contracts and transactions always use wei. web3.utils.toWei("0.1", "ether") returns "100000000000000000", and web3.utils.fromWei(balance, "ether") converts a balance for display.
Wei amounts quickly exceed JavaScript's safe integer limit of 253 − 1, which is only about 0.009 ether. web3.js v4 therefore returns balances, gas values and block numbers as BigInt values, shown with an n suffix such as 21000n. BigInt arithmetic must not be mixed with ordinary numbers, and amounts should be passed to the library as strings or BigInt values, never as floating point numbers.