Try it Live
Run Address examples in the interactive playground
- C
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)
c_int - PRIMITIVES_SUCCESS (0) on successExample:Format
Output format:0x + 40 lowercase hexadecimal characters
Total length: 42 characters
Example outputs:
0x0000000000000000000000000000000000000000(zero address)0x742d35cc6634c0532925a3b844bc9e7595f51e3e0xffffffffffffffffffffffffffffffffffffffff(max address)
Case Sensitivity
toHex() always returns lowercase, regardless of input format:
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
- toChecksummed - Convert to EIP-55 checksummed hex
- toShortHex - Convert to abbreviated display format
- fromHex - Parse from hex string
- Hex - Hex string utilities

