Skip to main content

Try it Live

Run Denomination examples in the interactive playground

Denomination

Type-safe Ethereum value denominations with compile-time unit tracking.
Start with Fundamentals to learn about Wei, Gwei, Ether, and unit conversions.

Overview

Branded types representing Ethereum denominations. Wei is a branded bigint (whole numbers only). Ether and Gwei are branded string types that support decimal values like "1.5". Each denomination prevents accidental unit mixing at compile time while enabling seamless conversions.

Quick Start

Types

Each denomination uses branded types for compile-time safety:
See Wei for details.

Conversion Constants

Wei uses integer arithmetic (bigint). Ether and Gwei use decimal strings to preserve fractional precision.

Interactive Converter

Try converting between denominations:

Denomination Table

UnitWeiGweiEtherCommon Use
Wei110^-910^-18Precise calculations, smallest unit
Gwei10^9110^-9Gas prices, transaction fees
Ether10^1810^91User-facing values, balances

API Variants

Two APIs for different use cases:

Branded API (Type-safe)

Requires branded types, compile-time safety:
Choose namespace for convenience, branded for type safety.

API Documentation

Wei

Smallest denomination for precise calculations and internal representation. View Wei →

Gwei

Gas price denomination, 1 billion Wei. View Gwei →

Ether

User-facing denomination, 1 quintillion Wei. View Ether →

BrandedWei

Type-safe Wei with BrandedUint data representation. View BrandedWei →

BrandedGwei

Type-safe Gwei with BrandedUint data representation. View BrandedGwei →

BrandedEther

Type-safe Ether with BrandedUint data representation. View BrandedEther →

Conversions

Converting between Wei, Gwei, and Ether with type safety. View Conversions →

WASM Implementation

WebAssembly-accelerated conversions compiled from Zig. View WASM →

Usage Patterns

Common patterns for gas calculations, transaction values, and conversions. View Usage Patterns →

Gas Calculator

Calculate transaction costs and convert between denominations and USD. View Gas Calculator →

Scale Visualization

Visual guides to understanding denomination relationships and magnitudes. View Scale Visualization →
Compile-time type safety prevents unit mixing bugs. Wei.Type and Gwei.Type are incompatible - explicit conversion required.

Type Safety

Each denomination prevents accidental mixing:

Decimal Precision

Ether and Gwei use decimal strings to preserve fractional values:
Round-trip conversions preserve full precision:

Uint256

Underlying 256-bit unsigned integer type for all denominations. View Uint256 →

Branded Types

Zero-overhead type branding pattern used throughout primitives. View Branded Types →

Chain

Network configuration with RPC endpoints and currency decimals. View Chain →

FeeMarket

EIP-1559 fee market dynamics and gas pricing. View FeeMarket →

GasConstants

Standard gas amounts for common operations. View GasConstants →