Ether (ETH) is the native cryptocurrency of Ethereum. Ether.Type is a brandedUint256 preventing accidental unit mixing.Common usage: Account balances, transaction values, user-facing amounts.
import * as Ether from 'tevm/Ether'import * as Uint from 'tevm/Uint'const ether = Ether(10n)const u256 = Ether.toU256(ether) // Uint.Type (unbranded)// Can now use with Uint operationsconst doubled = Uint.times(u256, Uint(2n))
Parameters:
ether: Ether.Type - Ether value
Returns:Uint.TypeNote: Removes type safety. Use for arithmetic operations requiring Uint.Type.Defined in: primitives/Denomination/Ether.ts:34
import * as Ether from 'tevm/Ether'import * as Wei from 'tevm/Wei'// Get balance from RPC (returns Wei)const balanceWei = Wei(5_250_000_000_000_000_000n)// Convert to Ether for displayconst balanceEther = Wei.toEther(balanceWei) // 5n Etherconsole.log(`Balance: ${balanceEther} ETH`)// Note: Fractional part truncated (should use Wei for display)
import * as Ether from 'tevm/Ether'import * as Wei from 'tevm/Wei'import * as Uint from 'tevm/Uint'const minimumEther = Ether(1n) // Require at least 1 ETHconst balanceWei = Wei(2_500_000_000_000_000_000n) // 2.5 ETH in Wei// Convert to same unit for comparisonconst minimumWei = Ether.toWei(minimumEther)const minimumU256 = Wei.toU256(minimumWei)const balanceU256 = Wei.toU256(balanceWei)if (balanceU`256 >= minimumU256`) { console.log("Sufficient balance")}
import * as Ether from 'tevm/Ether'// Standard amountsconst ZERO = Ether(0n)const ONE = Ether(1n)const TEN = Ether(10n)const HUNDRED = Ether(100n)// Minimum balances for contractsconst MIN_ACCOUNT_BALANCE = Ether(1n)const MIN_STAKING = Ether(32n) // Validator stake
Ether type prevents mixing with other denominations:
import * as Ether from 'tevm/Ether'import * as Gwei from 'tevm/Gwei'const balance = Ether(10n)const gasPrice = Gwei(50n)// ✗ Type error - cannot mix Ether and Gweiconst total = balance + gasPrice// ✓ Correct - explicit conversionconst gasPriceEther = Gwei.toEther(gasPrice)// (Though this makes little sense - Gwei should stay Gwei for gas)
Ether uses integer arithmetic. For fractional Ether:
import * as Ether from 'tevm/Ether'import * as Wei from 'tevm/Wei'// ✗ Fractional Ether lostconst ether = Ether(1n) // Can only represent whole Etherconst halfEther = Ether(0.5) // ✗ Not possible// ✓ Use Wei for fractional valuesconst halfEtherWei = Wei(500_000_000_000_000_000n) // 0.5 ETH// Convert back to Ether when neededconst ether = Wei.toEther(halfEtherWei) // 0n (truncates)
Recommendation: Store all values in Wei, display in Ether.