Skip to main content
Converts CallData to a hex-encoded string with 0x prefix. Primary method for serializing calldata for display or transmission.
WASM performance note: Simple string/hex conversions like toHex() usually do not get faster under WASM. Crossing the JS↔WASM boundary adds overhead, and JavaScript already has very fast built-ins for hex/string formatting. Prefer the default JS entrypoint for toHex()-style operations; reserve WASM for compute-heavy tasks (e.g., Keccak256 hashing, ABI/RLP encoding/decoding, secp256k1/BLS) where it shines.Voltaire’s WASM builds intentionally balance performance and bundle size. For maximum performance, build from source using the performance-optimized WASM target. See Build from Source: /dev/build-system#typescript-targets and WASM Build Modes: /dev/wasm#build-modes.

Signature

Parameters

  • calldata - CallData instance to convert

Returns

string - Hex-encoded string with 0x prefix

Examples

Format

Output always includes 0x prefix and lowercase hex:

Use Cases

JSON-RPC Transactions

Logging and Debugging

Block Explorers

Storage and Caching

Performance

String conversion is optimized but has overhead:
For performance-critical paths, keep data as Uint8Array:

Comparison with toBytes

Use when:
  • Displaying to users
  • Sending over JSON-RPC
  • Storing as text
  • Logging/debugging

Type Safety

Output is plain string (no branding):
  • toBytes - Convert to Uint8Array
  • fromHex - Parse hex string
  • Hex - Hex encoding utilities
  • decode - Decode to structured form