Skip to content

toHex

toHex(value, opts?): Hex

Encodes a string, number, bigint, or ByteArray into a hex string

Parameters

value: string | number | bigint | boolean | Uint8Array

Value to encode.

opts?: ToHexParameters

Options.

Returns

Hex value.

Example

import { toHex } from 'viem'
const data = toHex('Hello world')
// '0x48656c6c6f20776f726c6421'

Example

import { toHex } from 'viem'
const data = toHex(420)
// '0x1a4'

Example

import { toHex } from 'viem'
const data = toHex('Hello world', { size: 32 })
// '0x48656c6c6f20776f726c64210000000000000000000000000000000000000000'

Source

node_modules/.pnpm/viem@2.4.0_typescript@5.3.3_zod@3.22.4/node_modules/viem/_types/utils/encoding/toHex.d.ts:36


Generated using typedoc-plugin-markdown and TypeDoc