Convert between hex strings and byte arrays using Voltaire’s Hex primitive
import { Bytes } from '@tevm/voltaire/Bytes';
import * as Hex from '@tevm/voltaire/Hex';
// Encode bytes to hex string
const bytes = Bytes.from([72, 101, 108, 108, 111]); // "Hello" in bytes
const hexString = Hex.fromBytes(bytes);
// Decode hex string back to bytes
const decoded = Hex.toBytes(hexString);
// Create hex directly from string
const directHex = Hex.from("0x48656c6c6f");
examples/hex-and-bytes/hex-encode-decode.ts.Was this page helpful?
Suggestions