Encodes a string, number, bigint, or ByteArray into a hex string
Value to encode.
Optional
Options.
Hex value.
import { toHex } from 'viem'const data = toHex('Hello world')// '0x48656c6c6f20776f726c6421' Copy
import { toHex } from 'viem'const data = toHex('Hello world')// '0x48656c6c6f20776f726c6421'
import { toHex } from 'viem'const data = toHex(420)// '0x1a4' Copy
import { toHex } from 'viem'const data = toHex(420)// '0x1a4'
import { toHex } from 'viem'const data = toHex('Hello world', { size: 32 })// '0x48656c6c6f20776f726c64210000000000000000000000000000000000000000' Copy
import { toHex } from 'viem'const data = toHex('Hello world', { size: 32 })// '0x48656c6c6f20776f726c64210000000000000000000000000000000000000000'
Encodes a string, number, bigint, or ByteArray into a hex string