Skip to main content

Convert Between Wei, Ether, and Gwei

Balances and gas prices on Ethereum are stored in Wei — a unit so small that 1 ETH equals 10^18 Wei. As you saw in Query Balance, raw balance queries return Wei values. This guide covers all the conversion utilities you'll need to display human-readable amounts and work with gas prices in Gwei.

dotnet add package Nethereum.Web3

Wei to Ether

By default, balance queries return values in Wei — not easy to read unless you're talented at maths. Convert to Ether using the FromWei method:

using Nethereum.Web3;

var web3 = new Web3("https://mainnet.infura.io/v3/YOUR-PROJECT-ID");

var balance = await web3.Eth.GetBalance.SendRequestAsync(
"0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae");
Console.WriteLine("Balance in Wei: " + balance.Value);

// Convert from Wei to Ether
var balanceInEther = Web3.Convert.FromWei(balance.Value);
Console.WriteLine("Balance in Ether: " + balanceInEther);

Ether to Wei

Convert back to Wei using ToWei:

var backToWei = Web3.Convert.ToWei(balanceInEther);
Console.WriteLine("Balance back in Wei: " + backToWei);

Gwei Conversion

Gas prices are typically expressed in Gwei (1 Gwei = 1,000,000,000 Wei):

using Nethereum.Util;

var convert = UnitConversion.Convert;

// Wei to Gwei
var gweiValue = convert.FromWei(BigInteger.Parse("21000000000"), UnitConversion.EthUnit.Gwei);
// 21

// Gwei to Wei
var gweiInWei = convert.ToWei(21, UnitConversion.EthUnit.Gwei);
// 21000000000

Ether to Wei (Static)

var oneEtherInWei = UnitConversion.Convert.ToWei(1, UnitConversion.EthUnit.Ether);
// 1000000000000000000

Custom Decimal Places (ERC20 Tokens)

ERC20 tokens have varying decimal places. USDC and USDT use 6 decimals, not 18:

// USDC has 6 decimals
var usdcAmount = UnitConversion.Convert.FromWei(BigInteger.Parse("1000000"), 6);
// 1

var usdcInSmallestUnit = UnitConversion.Convert.ToWei(1m, 6);
// 1000000

All Ethereum Denominations

UnitWei ValueDecimals
Wei10
Kwei1,0003
Mwei1,000,0006
Gwei1,000,000,0009
Szabo10^1212
Finney10^1515
Ether10^1818
Kether10^2121

BigDecimal Precision

For very large values where decimal may lose precision:

var largeWei = BigInteger.Parse("123456789012345678901234567890");
var bigDecimal = UnitConversion.Convert.FromWeiToBigDecimal(
largeWei, UnitConversion.EthUnit.Ether);
var backToWei = UnitConversion.Convert.ToWei(bigDecimal, UnitConversion.EthUnit.Ether);
// largeWei == backToWei

Next Steps