Skip to main content

Try it Live

Run Denomination examples in the interactive playground

BrandedGwei

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

Overview

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

Type Definition

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

Construction

BrandedGwei.from(value)

Create BrandedGwei from numeric input.
Parameters:
  • value: bigint | number | string - Value to convert
Returns: BrandedGwei

BrandedGwei.fromWei(wei)

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

BrandedGwei.fromEther(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 Other Units

BrandedGwei.toWei(gwei)

Convert BrandedGwei to BrandedWei (multiply by 10^9).
Parameters:
  • gwei: BrandedGwei - Gwei amount
Returns: BrandedWei Formula: wei = gwei * 1_000_000_000

BrandedGwei.toEther(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 Base Type

BrandedGwei.toU256(gwei)

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

Constants

Usage Examples

Gas Price Calculation

Priority Fee Calculation

Conversion Chain

Display Gas Price

Type Safety

BrandedGwei prevents mixing denominations at compile time:

Performance

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

Common Gwei Values

When to Use BrandedGwei

Use BrandedGwei when:
  • Type safety is critical
  • Working with existing BrandedUint infrastructure
  • Building type-safe APIs
  • Performance-sensitive gas calculations