Skip to content

bytesToHex

bytesToHex(value, opts?): Hex

Encodes a bytes array into a hex string

Parameters

value: Uint8Array

Value to encode.

opts?: BytesToHexOpts

Options.

Returns

Hex

Hex value.

Examples

import { bytesToHex } from 'viem'
const data = bytesToHex(Uint8Array.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33])
// '0x48656c6c6f20576f726c6421'
import { bytesToHex } from 'viem'
const data = bytesToHex(Uint8Array.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]), { size: 32 })
// '0x48656c6c6f20576f726c64210000000000000000000000000000000000000000'

Source

node_modules/.pnpm/viem@2.13.6_bufferutil@4.0.8_typescript@5.4.5_utf-8-validate@6.0.4_zod@3.23.8/node_modules/viem/_types/utils/encoding/toHex.d.ts:91