Skip to main content
Returns the underlying Uint8Array representation of CallData. Zero-copy operation that provides access to raw bytes.

Signature

Parameters

  • calldata - CallData instance to convert

Returns

Uint8Array - Raw byte array (shares underlying buffer)

Examples

Zero-Copy Behavior

toBytes returns the same underlying buffer:
Important: Mutating bytes affects the original CallData.

Use Cases

Binary Protocols

File Operations

Performance-Critical Operations

WASM Interop

Performance

toBytes is effectively zero-cost:
Compare with toHex:
toBytes is ~24x faster than toHex for this workload.

Immutability Considerations

While CallData is conceptually immutable, toBytes exposes mutable buffer:
For public APIs, consider returning copies to maintain immutability guarantees.

Type Safety

Output is plain Uint8Array (no CallData brand):

Comparison with toHex

Advantages:
  • Zero-copy (24x faster)
  • Binary protocols (WebSocket, files)
  • WASM interop
  • Direct byte manipulation
Use for:
  • Performance-critical paths
  • Binary I/O
  • Cryptographic operations
  • Memory-efficient processing