Skip to main content

Try it Live

Run Address examples in the interactive playground

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

AddressLike Type

AddressLike is a union type accepting any input that can be coerced to an address:

Accepted Types

Number - Converted to 20-byte representation:
Bigint - Takes lower 160 bits:
String - Hex string with or without 0x prefix:
Uint8Array - Must be exactly 20 bytes:
For hex strings, always include 0x prefix to avoid ambiguity. Strings without 0x are parsed as hex but may cause confusion.

Performance

Zero-copy for Uint8Array and AddressType (no allocation). Conversion required for numbers, bigints, and strings (allocates new Uint8Array). For performance-critical code, prefer passing Uint8Array or AddressType directly.

See Also