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
BrandedUint properties - 32-byte Uint8Array with bigint arithmetic.
Construction
BrandedGwei.from(value)
Create BrandedGwei from numeric input.
value: bigint | number | string- Value to convert
BrandedGwei
BrandedGwei.fromWei(wei)
Convert BrandedWei to BrandedGwei (divide by 10^9).
wei: BrandedWei- Wei amount
BrandedGwei
Formula: gwei = wei / 1_000_000_000 (integer division)
BrandedGwei.fromEther(ether)
Convert BrandedEther to BrandedGwei (multiply by 10^9).
ether: BrandedEther- Ether amount
BrandedGwei
Formula: gwei = ether * 1_000_000_000
Conversions To Other Units
BrandedGwei.toWei(gwei)
Convert BrandedGwei to BrandedWei (multiply by 10^9).
gwei: BrandedGwei- Gwei amount
BrandedWei
Formula: wei = gwei * 1_000_000_000
BrandedGwei.toEther(gwei)
Convert BrandedGwei to BrandedEther (divide by 10^9).
gwei: BrandedGwei- Gwei amount
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).
gwei: BrandedGwei- Gwei amount
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
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
Related
- BrandedWei - Branded Wei type
- BrandedEther - Branded Ether type
- BrandedUint - Underlying branded Uint256 type
- Conversions - Converting between units

