ETH ↔ Wei ↔ Gwei Converter
Convert between Ethereum units (wei, gwei, ether, etc.). BigInt math, no precision loss.
ETH ↔ Wei ↔ Gwei Converter
1.01000.01000000.01000000000.01000000000000.01000000000000000.01000000000000000000Uses ethers.parseUnits / formatUnits (BigInt math — no floating-point loss).
Runs entirely in your browser. Your input never leaves your device.
What next?
How it works
The ETH unit hierarchy
Ether (ETH) is divisible to 18 decimal places. The smallest unit is wei — named after Wei Dai, the cryptographer who proposed b-money. The full hierarchy:
| Unit | Wei value | Common use | |------|-----------|------------| | wei | 1 | Smart contract internal math | | kwei (babbage) | 10³ | Rarely used | | mwei (lovelace) | 10⁶ | Rarely used | | gwei (shannon) | 10⁹ | Gas prices | | microether (szabo) | 10¹² | Occasionally in DeFi | | milliether (finney) | 10¹⁵ | Rarely used | | ether | 10¹⁸ | Human-facing balances |
In practice, you work with three units almost exclusively: wei for arithmetic inside contracts, gwei for gas pricing, and ether for displaying balances to users. The intermediate units (kwei, mwei, szabo, finney) appear mainly in old documentation and EIPs; modern tooling omits them.
Why wei exists and why it matters
Solidity and the EVM operate entirely in integers — there are no floating-point types. All value transfers happen in wei. If a contract receives 1 ETH, the EVM sees the integer 1000000000000000000 (10¹⁸). This design eliminates rounding errors in financial logic at the cost of requiring every developer to reason about very large integers.
The consequences are real: an off-by-one-decimal bug does not lose a few cents — it can lose 10× or 100× the intended amount. A function that expects wei but receives gwei will interpret 1 gwei (10⁹ wei) as 0.000000001 ETH, not the 1 ETH the caller intended.
The JavaScript number precision trap
JavaScript's Number type is a 64-bit IEEE 754 double. It can represent integers exactly up to 2⁵³ − 1 = 9,007,199,254,740,991. One ether in wei is 1,000,000,000,000,000,000 (10¹⁸) — larger than 2⁵³. Two ether is 2,000,000,000,000,000,000 — larger still. Any arithmetic on wei values using plain JS Number will silently lose precision:
// WRONG — silent precision loss
const oneEther = 1e18; // 1000000000000000000 ✓ (exact, lucky)
const twoEther = 2e18; // 2000000000000000000 ✓ (exact, lucky)
const weirdAmt = 1.5e18 + 1; // 1500000000000000001? No:
console.log(1500000000000000001) // → 1500000000000000000 ✗ (lost the +1)
The fix is BigInt (native in all modern JS/TS environments) or a library that wraps it:
// CORRECT — using BigInt
const oneEther = 1_000_000_000_000_000_000n;
const result = oneEther + 1n; // 1000000000000000001n ✓
This tool uses ethers.js v6 under the hood, which represents all amounts as BigInt internally. Conversion results are formatted as decimal strings, not floats, so the display is exact.
Using ethers.js parseUnits and formatUnits
The two functions you'll use daily in any Ethereum dapp:
import { parseUnits, formatUnits } from "ethers";
// User types "1.5" ETH → internal BigInt in wei
const weiAmount = parseUnits("1.5", "ether");
// → 1500000000000000000n
// Contract returns a wei BigInt → display to user
const display = formatUnits(weiAmount, "ether");
// → "1.5"
// Gas price: gwei ↔ wei
const gasPrice = parseUnits("20", "gwei"); // → 20000000000n
const gasPriceGwei = formatUnits(gasPrice, "gwei"); // → "20.0"
The second argument accepts either the unit name ("ether", "gwei", "wei") or the number of decimals as an integer. This generalizes to ERC-20 tokens: parseUnits("100", 6) for USDC (6 decimals), parseUnits("100", 18) for most other tokens.
Gas cost calculation
A transaction's ETH cost is:
gas cost (ETH) = gas used × gas price (in gwei) × 10⁻⁹
Or equivalently in wei:
gas cost (wei) = gas used × gas price (in wei)
A standard ETH transfer uses 21,000 gas. At 20 gwei gas price:
cost = 21,000 × 20 × 10⁻⁹ ETH = 0.00042 ETH = 420,000,000,000,000 wei
A complex DeFi swap might use 150,000–500,000 gas. Use the converter to check costs at current gas prices without mental arithmetic.
EIP-1559 base fee + priority fee
Since the London hard fork (August 2021), Ethereum gas pricing uses a two-component model:
- Base fee — algorithmically set by the protocol per block, burned (not paid to validators). Denominated in gwei.
- Priority fee (tip) — paid directly to the validator as an incentive to include your transaction. Denominated in gwei. Typical range: 0.1–2 gwei in calm conditions, up to 10+ gwei during congestion.
Your wallet sets a max fee per gas (the ceiling you'll pay) and a max priority fee. The actual fee paid is:
actual fee per gas = min(max_fee, base_fee + priority_fee)
When debugging a transaction receipt, the effectiveGasPrice field is the actual fee per gas in wei. Use this converter to translate that value to gwei for comparison against current base fees.
Debugging transaction receipts
When inspecting a raw transaction receipt (from eth_getTransactionReceipt), several fields are in wei:
value— ETH transferred, in weigasPrice/effectiveGasPrice— fee per gas unit, in weicumulativeGasUsed— gas accumulated in the block up to this tx
Convert effectiveGasPrice to gwei to compare it against block explorer readings. Multiply effectiveGasPrice × gasUsed to get the total fee paid in wei, then convert to ETH for the dollar-cost sanity check.
Common developer mistakes
-
Dividing by 1e18 instead of 10n¹⁸n** in a JS context.** The float
1e18is fine for the specific value of 10¹⁸, but arithmetic around it loses bits. Always use BigInt orformatUnits. -
Confusing ERC-20 token decimals with ETH decimals. USDC uses 6 decimals; DAI uses 18; some tokens use 8 (like many bridged BTC).
parseUnits("1", 6)for 1 USDC is not the same asparseUnits("1", 18)for 1 ETH. -
Displaying raw wei to users. A balance of
50000000000000000wei looks like gibberish. AlwaysformatUnitsbefore display. -
Storing wei amounts in a SQL
INTEGERcolumn. PostgreSQL'sINTEGERtops out at ~2.1 billion;BIGINTat ~9.2 × 10¹⁸ — which barely fits 9 ETH in wei. UseNUMERICor store as aTEXTdecimal string.
Privacy
All conversions run locally in your browser via ethers.js. No values are sent to any server.
FAQ
What is wei and why does Ethereum use it?
Wei is the smallest indivisible unit of ether — 1 ETH equals 10¹⁸ wei. The EVM has no floating-point arithmetic, so all on-chain value transfers are integer wei amounts. Using the smallest unit for internal math eliminates rounding errors in financial logic. The name honors Wei Dai, the cryptographer who described b-money, a conceptual predecessor to Bitcoin.
Why can't I just use JavaScript Number for wei values?
JavaScript Number is a 64-bit IEEE 754 double, which can represent integers exactly only up to 2⁵³ − 1 (about 9 × 10¹⁵). One ETH in wei is 10¹⁸ — larger than that limit. Arithmetic on wei using plain Number silently loses precision for any amount above ~9 ETH. Always use BigInt or a library like ethers.js that wraps BigInt internally.
What is gwei and when do I use it?
Gwei (gigawei) equals 10⁹ wei. It is the standard unit for gas prices because it is a human-readable scale — current Ethereum gas prices range from single digits to low hundreds of gwei. When your wallet shows "gas price: 15 gwei", that is 15,000,000,000 wei per unit of gas consumed.
How do I calculate the total fee for a transaction?
Multiply gas used by the effective gas price: fee (wei) = gasUsed × effectiveGasPrice. Both values appear in the transaction receipt. Convert the result from wei to ETH using this tool to get the human-readable cost. For a standard ETH transfer (21,000 gas) at 20 gwei, the fee is 0.00042 ETH.
What changed with EIP-1559?
EIP-1559 (London fork, August 2021) replaced the single gas price auction with a base fee plus priority fee model. The base fee is burned and algorithmically adjusted per block; the priority fee (tip) goes to the validator. You set a max fee per gas as a ceiling. The actual fee paid is min(maxFee, baseFee + priorityFee). This made fee estimation more predictable and reduced overpayment.
Does this converter work for ERC-20 tokens?
Partially. ERC-20 tokens use the same wei/unit pattern but with token-specific decimal counts — USDC has 6 decimals, most tokens have 18, some wrapped assets have 8. The converter's "custom decimals" mode accepts any decimal count so you can convert any ERC-20 amount. The unit names (wei, gwei, ether) on the ETH side are just labels for powers of 10 — the same math applies.
How should I store wei amounts in a database?
Do not use INTEGER or BIGINT SQL columns — PostgreSQL BIGINT maxes at ~9.2 × 10¹⁸, which fits only ~9 ETH before overflow. Use NUMERIC (arbitrary precision) or store amounts as a TEXT decimal string. When reading back, parse with BigInt() or ethers.parseUnits before doing arithmetic.
Why does my smart contract receive the wrong amount?
Almost always a unit mismatch. If your frontend sends parseUnits("1", "gwei") (= 10⁹ wei) but the contract expects the amount in wei thinking it is 1 ETH, you have sent 10⁻⁹ ETH instead of 1 ETH. Systematically decide at every layer whether you are working in wei or ether, add unit suffixes to variable names (amountWei, priceGwei), and validate with this converter before deploying.