Try it Live
Run Address examples in the interactive playground
- C
char* address_to_short_hex(address_t address, uint8_t prefix_len, uint8_t suffix_len, allocator_t allocator)
Format address as shortened hex string with ellipsis. Caller must free returned string.Parameters:address: address_t- Address to format (20 bytes)prefix_len: uint8_t- Characters after0xto showsuffix_len: uint8_t- Characters at end to showallocator: allocator_t- Memory allocator for result string
char* - Shortened hex string (must be freed by caller)Example:- Result string allocated by provided allocator
- Caller responsible for freeing returned string
- Length:
2 + prefix_len + 3 + suffix_len + 1bytes (including null terminator)
Format
Output pattern:0x{prefix}...{suffix}
Default lengths: prefix=6, suffix=4
Total length: 2 + prefix + 3 + suffix characters
Example outputs:
"0x742d35...1e3e"(default: 6+4 = 15 chars total)"0x742d35Cc...f51e3e"(custom: 8+6 = 19 chars total)"0x0000...0000"(zero address)
Use Cases
UI Display
Show addresses in constrained spaces:Mobile Interfaces
Optimize for small screens:Transaction Lists
Display sender/recipient in transaction tables:Notifications
Show addresses in toast notifications:Length Constraints
IfprefixLength + suffixLength >= 40, returns full address:
Visual Comparison
Best Practices
Always provide full address in tooltip/title:- Mobile: 4+4 (minimal)
- Desktop lists: 6+4 (default)
- Detailed views: 8+6 or full
- Copy operations: Always use full address
Accessibility
Ensure screen readers get full address:Performance
No cryptographic operations - Simple string slicing. Time complexity: O(1) constant time. Memory: Creates single new string. Very efficient for display purposes.See Also
- toHex - Convert to full lowercase hex
- toChecksummed - Convert to EIP-55 checksummed hex
- fromHex - Parse from hex string

