> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Address.from

> Universal constructor for creating addresses from various input types

<Card title="Try it Live" icon="play" href="https://playground.tevm.sh?example=primitives/address.ts">
  Run Address examples in the interactive playground
</Card>

<Tabs>
  <Tab title="C">
    ## `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 otherwise

    **Example:**

    ```c theme={null}
    #include "primitives.h"

    // From hex string
    PrimitivesAddress addr1;
    int result = primitives_address_from_hex("0x742d35Cc6634C0532925a3b844Bc9e7595f51e3e", &addr1);
    if (result != PRIMITIVES_SUCCESS) {
        // Handle error
    }

    // From hex without prefix
    PrimitivesAddress addr2;
    result = primitives_address_from_hex("742d35Cc6634C0532925a3b844Bc9e7595f51e3e", &addr2);

    // From number (converted to hex first)
    PrimitivesAddress addr3;
    result = primitives_address_from_hex("0x0000000000000000000000000000000000000045", &addr3);
    ```

    **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](https://github.com/evmts/voltaire/blob/main/src/primitives.h#L103)
  </Tab>
</Tabs>

## AddressLike Type

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

```typescript theme={null}
type AddressLike =
  | number
  | bigint
  | string
  | Uint8Array
  | AddressType
  | Address
```

### Accepted Types

**Number** - Converted to 20-byte representation:

```typescript theme={null}
const addr = Address(69)
// 0x0000000000000000000000000000000000000045
```

**Bigint** - Takes lower 160 bits:

```typescript theme={null}
const addr = Address(0x742d35Cc6634C0532925a3b844Bc9e7595f251e3n)
```

**String** - Hex string with or without `0x` prefix:

```typescript theme={null}
const addr1 = Address("0x742d35Cc6634C0532925a3b844Bc9e7595f51e3e")
const addr2 = Address("742d35Cc6634C0532925a3b844Bc9e7595f51e3e")
```

**Uint8Array** - Must be exactly 20 bytes:

```typescript theme={null}
const bytes = new Uint8Array(20)
const addr = Address(bytes)
```

<Warning title="String Interpretation">
  For hex strings, always include `0x` prefix to avoid ambiguity. Strings without `0x` are parsed as hex but may cause confusion.
</Warning>

## 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

* [fromHex](/primitives/address/from-hex) - Parse hex string directly
* [fromBytes](/primitives/address/from-bytes) - Create from Uint8Array directly
* [fromNumber](/primitives/address/from-number) - Create from number/bigint directly
* [fromPrivateKey](/primitives/address/from-private-key) - Derive from private key
* [fromPublicKey](/primitives/address/from-public-key) - Derive from public key
