Skip to main content

Try it Live

Run Address examples in the interactive playground
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.
View the complete executable example at playground/src/examples/primitives/address/to-hex.ts.
WASM performance note: toHex() is a simple conversion that generally does not run faster under WASM. The JS↔WASM boundary adds overhead, while JavaScript’s built-ins already handle hex/string formatting efficiently. Prefer the default JS entrypoint for toHex() and similar conversions; use WASM for compute-heavy operations (Keccak256 hashing, ABI/RLP encoding/decoding, secp256k1/BLS) where performance gains are significant.Voltaire’s WASM builds intentionally optimize for both performance and bundle size. For maximum performance, build from source with the performance-optimized WASM target. See /dev/build-system#typescript-targets and /dev/wasm#build-modes.

primitives_address_to_hex(address: *const PrimitivesAddress, buf: [*]u8): c_int

Convert address to hex string with 0x prefix. Buffer must be at least 42 bytes.Parameters:
  • address: *const PrimitivesAddress - Address to convert (20 bytes)
  • buf: [*]u8 - Output buffer for hex string (must be at least 42 bytes)
Returns: c_int - PRIMITIVES_SUCCESS (0) on successExample:
Defined in: c_api.zig:55

Format

Output format: 0x + 40 lowercase hexadecimal characters Total length: 42 characters Example outputs:
  • 0x0000000000000000000000000000000000000000 (zero address)
  • 0x742d35cc6634c0532925a3b844bc9e7595f51e3e
  • 0xffffffffffffffffffffffffffffffffffffffff (max address)

Case Sensitivity

toHex() always returns lowercase, regardless of input format:
For checksummed output, use toChecksummed() instead.

Use Cases

Display and Logging

Storage and Serialization

Comparison and Hashing

Database Queries

Performance

Zero allocation - Creates new string but no intermediate buffers. Time complexity: O(n) where n = 20 bytes (constant time). String concatenation: Efficient for this fixed size (40 hex chars). For repeated conversions, consider caching the result:

Comparison with Other Formats

See Also