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-bytes.ts.

primitives_address_to_bytes(PrimitivesAddress address, uint8_t* out_bytes): void

Convert address to byte array in C. Copies 20 bytes to provided buffer.Parameters:
  • address: PrimitivesAddress - Address to convert
  • out_bytes: uint8_t* - Buffer for output bytes (must be at least 20 bytes)
Returns: void - Bytes written to out_bytesExample:
Memory:
  • No allocation - copies to provided buffer
  • Caller must ensure buffer is at least 20 bytes
  • Safe to use stack-allocated buffer
Direct Access:Since PrimitivesAddress is a struct containing a 20-byte array, you can access bytes directly:
Defined in: primitives.h:146

Memory Behavior

TypeScript/JavaScript:
  • Returns a copy of the underlying bytes
  • Safe to modify returned array without affecting original
  • No aliasing between address and returned bytes
Zig:
  • Direct access to fixed-size array
  • Copying requires explicit @memcpy
  • Stack-allocated by default

Use Cases

Binary Protocols

Serialize addresses for binary protocols:

Hash Computation

Include address in hash calculations:

Database Storage

Store addresses as binary blobs:

Network Transmission

Send addresses over WebSocket or other binary protocols:

ABI Encoding

Convert to bytes for ABI encoding:

Direct Access

Since AddressType is a Uint8Array, you can access bytes directly:
When to use toBytes():
  • Need a mutable copy
  • Want to emphasize byte conversion
  • Passing to APIs expecting Uint8Array (not branded type)
When to access directly:
  • Reading bytes without modification
  • Iterating over bytes
  • Using array methods

Performance

Memory: Creates new Uint8Array (20 byte allocation) Time complexity: O(n) where n = 20 (constant time) Copy overhead: Minimal for 20 bytes For performance-critical code, access bytes directly instead:

Comparison with Other Conversions

See Also