Try it Live
Run Denomination examples in the interactive playground
Conversions
Type-safe conversions between Wei, Gwei, and Ether denominations.Overview
Each denomination type provides conversion methods to other units. All conversions use integer arithmetic - fractional values truncate (round down).Conversion Table
| From | To | Function | Formula | Example |
|---|---|---|---|---|
| Wei | Gwei | Wei.toGwei(wei) | wei / 10^9 | 1_000_000_000n Wei → 1n Gwei |
| Wei | Ether | Wei.toEther(wei) | wei / 10^18 | 1_000_000_000_000_000_000n Wei → 1n Ether |
| Gwei | Wei | Gwei.toWei(gwei) | gwei * 10^9 | 1n Gwei → 1_000_000_000n Wei |
| Gwei | Ether | Gwei.toEther(gwei) | gwei / 10^9 | 1_000_000_000n Gwei → 1n Ether |
| Ether | Wei | Ether.toWei(ether) | ether * 10^18 | 1n Ether → 1_000_000_000_000_000_000n Wei |
| Ether | Gwei | Ether.toGwei(ether) | ether * 10^9 | 1n Ether → 1_000_000_000n Gwei |
Wei Conversions
- Wei → Gwei
- Wei → Ether
- Wei ← Other Units
gwei = wei / 1_000_000_000 (integer division)Gwei Conversions
- Gwei → Wei
- Gwei → Ether
- Gwei ← Other Units
wei = gwei * 1_000_000_000Ether Conversions
- Ether → Wei
- Ether → Gwei
- Ether ← Other Units
wei = ether * 1_000_000_000_000_000_000Conversion Patterns
Gas Price Calculation
Balance Display
Multi-Step Conversion
Comparing Different Units
Integer Division Behavior
Truncation Examples
Avoiding Truncation
Round-Trip Safety
Safe Round Trips (No Loss)
Unsafe Round Trips (Loss)
Best Practices
1. Convert to Smallest Unit Early
2. Use Type System for Safety
3. Display in Appropriate Unit
Conversion Constants
All conversions based on these constants:WASM Acceleration
All conversions available in WebAssembly:Related
- Wei - Smallest denomination
- Gwei - Gas price denomination
- Ether - User-facing denomination
- Usage Patterns - Common patterns
- Uint256 - Underlying numeric type

