BrandedWei is a branded BrandedUint (Uint8Array-based) providing compile-time type safety for Wei values with zero-overhead direct data representation.
Convert BrandedGwei to BrandedWei (multiply by 10^9).
import * as BrandedGwei from 'tevm/BrandedGwei'import * as BrandedWei from 'tevm/BrandedWei'const gwei = BrandedGwei(50n)const wei = BrandedWei.fromGwei(gwei) // 50_000_000_000n Wei
Convert BrandedEther to BrandedWei (multiply by 10^18).
import * as BrandedEther from 'tevm/BrandedEther'import * as BrandedWei from 'tevm/BrandedWei'const ether = BrandedEther(1n)const wei = BrandedWei.fromEther(ether) // 1_000_000_000_000_000_000n Wei
Convert BrandedWei to raw BrandedUint (removes denomination branding).
import * as BrandedWei from 'tevm/BrandedWei'import * as BrandedUint from 'tevm/BrandedUint'const wei = BrandedWei(1_000_000_000n)const u256 = BrandedWei.toU256(wei) // BrandedUint (no denomination)// Can use with BrandedUint operationsconst doubled = BrandedUint.times(u256, BrandedUint(2n))
Parameters:
wei: BrandedWei - Wei amount
Returns:BrandedUintNote: Removes denomination type safety. Use for arithmetic requiring BrandedUint.
import * as BrandedWei from 'tevm/BrandedWei'import * as BrandedGwei from 'tevm/BrandedGwei'import * as BrandedEther from 'tevm/BrandedEther'// Start with Etherconst ether = BrandedEther(1n)// Convert to Weiconst wei = BrandedEther.toWei(ether) // 1_000_000_000_000_000_000n// Convert to Gweiconst gwei = BrandedWei.toGwei(wei) // 1_000_000_000n// Back to Etherconst etherAgain = BrandedGwei.toEther(gwei) // 1n