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/from-hex.ts.

primitives_address_from_hex(const char* hex, PrimitivesAddress* out_address): int

Create address from hex string in C. Accepts hex strings with or without 0x prefix.Parameters:
  • hex: const char* - Hex string (with or without 0x prefix)
  • out_address: PrimitivesAddress* - Pointer to output address struct (20 bytes)
Returns: int - PRIMITIVES_SUCCESS (0) on success, error code otherwiseExample:
Error Handling:
  • Returns non-zero error code on failure
  • Check result before using out_address
  • Common errors: invalid hex format, incorrect length
Memory: No allocation - address is copied to provided struct.Defined in: primitives.h:103

Format Requirements

Length (implementation-dependent): TypeScript implementations (Class API):
  • Requires 0x prefix: exactly 42 characters total
Zig and C implementations:
  • Accepts both formats:
    • With 0x prefix: exactly 42 characters
    • Without 0x prefix: exactly 40 characters
Characters:
  • Valid: 0-9, a-f, A-F
  • Invalid: g-z, G-Z, whitespace, special characters
Case sensitivity:
  • Parsing is case-insensitive
  • Both lowercase and uppercase hex are accepted
  • Mixed-case (EIP-55 checksummed) addresses are valid

Error Handling

Validation Before Parsing

Use Address.isValid() to check before parsing:

EIP-55 Checksums

fromHex() accepts checksummed addresses but does not validate checksums. Use isValidChecksum() to validate before parsing:

See Also