Signature
- Namespace
- Class
Parameters
- calldata - CallData instance to convert
Returns
Uint8Array - Raw byte array (shares underlying buffer)
Examples
- Basic Usage
- Zero-Copy
- Class API
Zero-Copy Behavior
toBytes returns the same underlying buffer:
Use Cases
Binary Protocols
File Operations
Performance-Critical Operations
WASM Interop
Performance
toBytes is effectively zero-cost:
toHex:
toBytes is ~24x faster than toHex for this workload.
Immutability Considerations
While CallData is conceptually immutable,toBytes exposes mutable buffer:
- Defensive Copy
- Direct Access
Type Safety
Output is plain Uint8Array (no CallData brand):Comparison with toHex
- When to use toBytes
- When to use toHex
Advantages:
- Zero-copy (24x faster)
- Binary protocols (WebSocket, files)
- WASM interop
- Direct byte manipulation
- Performance-critical paths
- Binary I/O
- Cryptographic operations
- Memory-efficient processing
Related
- toHex - Convert to hex string
- fromBytes - Create from Uint8Array
- getSelector - Extract selector bytes
- equals - Compare calldata instances

