Skip to main content

Try it Live

Run Denomination examples in the interactive playground

BrandedEther

Data-first branded Ether type - BrandedUint representing Ether denomination with zero-overhead runtime.

Overview

BrandedEther is a branded BrandedUint (Uint8Array-based) providing compile-time type safety for Ether values with zero-overhead direct data representation.

Type Definition

Inherits all BrandedUint properties - 32-byte Uint8Array with bigint arithmetic.

Construction

BrandedEther.from(value)

Create BrandedEther from numeric input.
Parameters:
  • value: bigint | number | string - Value to convert
Returns: BrandedEther Note: Fractional numbers truncate to integer Ether.

BrandedEther.fromWei(wei)

Convert BrandedWei to BrandedEther (divide by 10^18).
Parameters:
  • wei: BrandedWei - Wei amount
Returns: BrandedEther Formula: ether = wei / 1_000_000_000_000_000_000 (integer division)

BrandedEther.fromGwei(gwei)

Convert BrandedGwei to BrandedEther (divide by 10^9).
Parameters:
  • gwei: BrandedGwei - Gwei amount
Returns: BrandedEther Formula: ether = gwei / 1_000_000_000 (integer division)

Conversions To Other Units

BrandedEther.toWei(ether)

Convert BrandedEther to BrandedWei (multiply by 10^18).
Parameters:
  • ether: BrandedEther - Ether amount
Returns: BrandedWei Formula: wei = ether * 1_000_000_000_000_000_000

BrandedEther.toGwei(ether)

Convert BrandedEther to BrandedGwei (multiply by 10^9).
Parameters:
  • ether: BrandedEther - Ether amount
Returns: BrandedGwei Formula: gwei = ether * 1_000_000_000

Conversions To Base Type

BrandedEther.toU256(ether)

Convert BrandedEther to raw BrandedUint (removes denomination branding).
Parameters:
  • ether: BrandedEther - Ether amount
Returns: BrandedUint Note: Removes denomination type safety. Use for arithmetic requiring BrandedUint.

Constants

Usage Examples

User Balance Display

Transaction Value

Balance Operations

Conversion Chain

Fractional Display

Type Safety

BrandedEther prevents mixing denominations at compile time:

Performance

BrandedEther uses direct Uint8Array representation:
  • Zero wrapper overhead
  • Direct bigint arithmetic
  • Optimal for hot paths
  • Same memory layout as BrandedUint
For balance calculations in tight loops, prefer BrandedEther over Ether namespace.

Common Ether Values

Integer Division Notes

All conversions to Ether use integer division. Fractional Wei/Gwei amounts truncate:
For fractional display, work with Wei and format manually (see Fractional Display example above).

When to Use BrandedEther

Use BrandedEther when:
  • Type safety is critical
  • Working with existing BrandedUint infrastructure
  • Building type-safe APIs
  • Performance-sensitive balance operations