Skip to main content

Try it Live

Run Address examples in the interactive playground

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 after 0x to show
  • suffix_len: uint8_t - Characters at end to show
  • allocator: allocator_t - Memory allocator for result string
Returns: char* - Shortened hex string (must be freed by caller)Example:
Memory Management:
  • Result string allocated by provided allocator
  • Caller responsible for freeing returned string
  • Length: 2 + prefix_len + 3 + suffix_len + 1 bytes (including null terminator)
Defined in: primitives.h

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

If prefixLength + suffixLength >= 40, returns full address:

Visual Comparison

Best Practices

Always provide full address in tooltip/title:
Use consistent lengths across your UI:
Consider context when choosing lengths:
  • 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