BrandedGwei is a branded BrandedUint (Uint8Array-based) providing compile-time type safety for Gwei values with zero-overhead direct data representation.
Convert BrandedEther to BrandedGwei (multiply by 10^9).
import * as BrandedEther from 'tevm/BrandedEther'import * as BrandedGwei from 'tevm/BrandedGwei'const ether = BrandedEther(1n)const gwei = BrandedGwei.fromEther(ether) // 1_000_000_000n Gwei
Convert BrandedGwei to raw BrandedUint (removes denomination branding).
import * as BrandedGwei from 'tevm/BrandedGwei'import * as BrandedUint from 'tevm/BrandedUint'const gwei = BrandedGwei(50n)const u256 = BrandedGwei.toU256(gwei) // BrandedUint (no denomination)// Can use with BrandedUint operationsconst doubled = BrandedUint.times(u256, BrandedUint(2n))
Parameters:
gwei: BrandedGwei - Gwei amount
Returns:BrandedUintNote: Removes denomination type safety. Use for arithmetic requiring BrandedUint.
import * as BrandedGwei from 'tevm/BrandedGwei'import * as BrandedWei from 'tevm/BrandedWei'import * as BrandedUint from 'tevm/BrandedUint'// Gas price from RPC (often in Gwei)const gasPriceGwei = BrandedGwei(50n)// Convert to Wei for transactionconst gasPriceWei = BrandedGwei.toWei(gasPriceGwei)// Calculate total costconst gasUsed = BrandedUint(21_000n)const gasPriceU256 = BrandedWei.toU256(gasPriceWei)const totalCost = BrandedUint.times(gasPriceU256, gasUsed)console.log(`Total: ${BrandedWei(totalCost)} Wei`)
import * as BrandedGwei from 'tevm/BrandedGwei'import * as BrandedWei from 'tevm/BrandedWei'import * as BrandedEther from 'tevm/BrandedEther'// Start with Gwei (common for gas prices)const gwei = BrandedGwei(50n)// Convert to Wei (for calculations)const wei = BrandedGwei.toWei(gwei) // 50_000_000_000n// Convert to Ether (for display, requires full Ether)const largeGwei = BrandedGwei(1_000_000_000n) // 1 ETHconst ether = BrandedGwei.toEther(largeGwei) // 1n
import * as BrandedGwei from 'tevm/BrandedGwei'import * as BrandedWei from 'tevm/BrandedWei'// RPC returns Weiconst gasPriceWei = BrandedWei(50_000_000_000n)// Convert to Gwei for user displayconst gasPriceGwei = BrandedWei.toGwei(gasPriceWei)console.log(`Gas price: ${gasPriceGwei} Gwei`) // "Gas price: 50 Gwei"