Skip to main content

Try it Live

Run Denomination examples in the interactive playground

Wei

Smallest Ethereum denomination (10^-18 Ether) for precise value calculations.

Overview

Wei is the atomic unit of Ether. All Ethereum values are ultimately represented in Wei internally. Wei.Type is a branded Uint256 preventing accidental unit mixing.

Type Definition

Construction

Wei.from(value)

Create Wei from numeric value.
Parameters:
  • value: bigint | number | string - Value to convert to Wei
Returns: Wei.Type Note: Uses Uint.from internally for conversion. Defined in: primitives/Denomination/Wei.ts:10

Conversions From Other Units

Wei.fromGwei(gwei)

Convert Gwei to Wei (multiply by 10^9).
Parameters:
  • gwei: Gwei.Type - Gwei value
Returns: Wei.Type Formula: wei = gwei * 1_000_000_000 Defined in: primitives/Denomination/Wei.ts:14

Wei.fromEther(ether)

Convert Ether to Wei (multiply by 10^18).
Parameters:
  • ether: Ether.Type - Ether value
Returns: Wei.Type Formula: wei = ether * 1_000_000_000_000_000_000 Defined in: primitives/Denomination/Wei.ts:19

Conversions To Other Units

Wei.toGwei(wei)

Convert Wei to Gwei (divide by 10^9).
Parameters:
  • wei: Wei.Type - Wei value
Returns: Gwei.Type Formula: gwei = wei / 1_000_000_000 (integer division) Defined in: primitives/Denomination/Wei.ts:24

Wei.toEther(wei)

Convert Wei to Ether (divide by 10^18).
Parameters:
  • wei: Wei.Type - Wei value
Returns: Ether.Type Formula: ether = wei / 1_000_000_000_000_000_000 (integer division) Defined in: primitives/Denomination/Wei.ts:29

Conversions To Base Type

Wei.toU256(wei)

Convert Wei to raw Uint256 (removes branding).
Parameters:
  • wei: Wei.Type - Wei value
Returns: Uint.Type Note: Removes type safety. Use for arithmetic operations requiring Uint.Type. Defined in: primitives/Denomination/Wei.ts:34

Usage Examples

Gas Cost Calculation

Transaction Value

Precise Accounting

Conversion Constants

Common Wei Values

Type Safety

Wei type prevents mixing with other denominations:

WASM Acceleration

Wei conversions available in WebAssembly for performance:
See WASM for details.
  • Gwei - Gas price denomination
  • Ether - User-facing denomination
  • Conversions - Converting between units
  • Uint256 - Underlying numeric type