Convert Uint256 to hex string with 0x prefix
import { UintSchema } from '@tevm/voltaire/Uint/effect' const u = UintSchema.from(255n) u.toHex(false) // '0xff'
Uint.toHex(Uint(0n)) // "0x0" Uint.toHex(Uint(1n)) // "0x1" Uint.toHex(Uint(15n)) // "0xf" Uint.toHex(Uint(16n)) // "0x10" Uint.toHex(Uint(255n)) // "0xff" Uint.toHex(Uint(256n)) // "0x100"
Uint.toHex(Uint(0xdeadbeefn)) // "0xdeadbeef"
// Never returns without prefix Uint.toHex(Uint(255n)) // "0xff" (not "ff")
const value = Uint(12345n) console.log(`Value: ${Uint.toHex(value)}`) // "Value: 0x3039"
// Format for JSON-RPC const balance = Uint(1000000000000000000n) const rpcValue = Uint.toHex(balance) // "0xde0b6b3a7640000" await eth_sendTransaction({ value: rpcValue })
const slot = Uint(5n) const key = Uint.toHex(slot) // "0x5"
Was this page helpful?