Try it Live
Run Denomination examples in the interactive playground
BrandedWei
Data-first branded Wei type -BrandedUint representing Wei denomination with zero-overhead runtime.
Overview
BrandedWei is a branded BrandedUint (Uint8Array-based) providing compile-time type safety for Wei values with zero-overhead direct data representation.
Type Definition
BrandedUint properties - 32-byte Uint8Array with bigint arithmetic.
Construction
BrandedWei.from(value)
Create BrandedWei from numeric input.
value: bigint | number | string- Value to convert
BrandedWei
BrandedWei.fromGwei(gwei)
Convert BrandedGwei to BrandedWei (multiply by 10^9).
gwei: BrandedGwei- Gwei amount
BrandedWei
Formula: wei = gwei * 1_000_000_000
BrandedWei.fromEther(ether)
Convert BrandedEther to BrandedWei (multiply by 10^18).
ether: BrandedEther- Ether amount
BrandedWei
Formula: wei = ether * 1_000_000_000_000_000_000
Conversions To Other Units
BrandedWei.toGwei(wei)
Convert BrandedWei to BrandedGwei (divide by 10^9).
wei: BrandedWei- Wei amount
BrandedGwei
Formula: gwei = wei / 1_000_000_000 (integer division)
BrandedWei.toEther(wei)
Convert BrandedWei to BrandedEther (divide by 10^18).
wei: BrandedWei- Wei amount
BrandedEther
Formula: ether = wei / 1_000_000_000_000_000_000 (integer division)
Conversions To Base Type
BrandedWei.toU256(wei)
Convert BrandedWei to raw BrandedUint (removes denomination branding).
wei: BrandedWei- Wei amount
BrandedUint
Note: Removes denomination type safety. Use for arithmetic requiring BrandedUint.
Constants
Usage Examples
Gas Cost Calculation
Transaction Value
Conversion Chain
Type Safety
BrandedWei prevents mixing denominations at compile time:Performance
BrandedWei uses direct Uint8Array representation:- Zero wrapper overhead
- Direct bigint arithmetic
- Optimal for hot paths
- Same memory layout as BrandedUint
When to Use BrandedWei
Use BrandedWei when:- Type safety is critical
- Working with existing BrandedUint infrastructure
- Building type-safe APIs
- Performance-sensitive code paths
Related
- BrandedGwei - Branded Gwei type
- BrandedEther - Branded Ether type
- BrandedUint - Underlying branded Uint256 type
- Conversions - Converting between units

