# client

Creates a live CLIENT from a TRANSPORT or restores retained execution state by execution ID. An optional expected chain ID rejects state from another chain.

Canonical HTML: <https://determica.com/docs/functions/client>

- Kind: scalar function
- Category: [Clients and state contexts](/docs/category/clients-and-state-contexts.md)
- Tags: Client

Creates a live CLIENT from a TRANSPORT or restores retained execution state by execution ID. An optional expected chain ID rejects state from another chain.

## Overload 1: client(TRANSPORT)

```sql
client(TRANSPORT)
```

Creates a live CLIENT from the TRANSPORT's declared chain id without sending an RPC request.

- Kind: scalar
- Execution context: Offline
- Behavior: Live Client Constructor
- Execution modes: Live Client
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `transport` (TRANSPORT; required; positional) — TRANSPORT that provides the chain endpoint and request policy for a live CLIENT.

### Returns

Live CLIENT

Returns a live CLIENT. Its state follows the TRANSPORT's chain until pin resolves it to one block.

- `client` (CLIENT)

Live CLIENT. Returns a live CLIENT. Its state follows the TRANSPORT's chain until pin resolves it to one block.

## Overload 2: client(TRANSPORT, UBIGINT)

```sql
client(TRANSPORT, UBIGINT)
```

Creates a live CLIENT only when the TRANSPORT's declared chain id matches expected_chain_id.

- Kind: scalar
- Execution context: Offline
- Behavior: Live Client Constructor
- Execution modes: Live Client
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `transport` (TRANSPORT; required; positional) — TRANSPORT that provides the chain endpoint and request policy for a live CLIENT.
- `expected_chain_id` (UBIGINT; required; positional) — Required EVM chain id. CLIENT creation fails locally when the TRANSPORT declares another chain.

### Returns

Live CLIENT

Returns a live CLIENT. Its state follows the TRANSPORT's chain until pin resolves it to one block.

- `client` (CLIENT)

Live CLIENT. Returns a live CLIENT. Its state follows the TRANSPORT's chain until pin resolves it to one block.

## Overload 3: client(UUID)

```sql
client(UUID)
```

Restores a CLIENT from retained execution state without attaching a TRANSPORT.

- Kind: scalar
- Execution context: Offline
- Behavior: Execution Client Constructor
- Execution modes: Execution Client
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `execution_id` (UUID; required; positional) — UUID for retained execution state in Determica's local catalog.

### Returns

Execution CLIENT

Returns a CLIENT for retained execution state. Attach a TRANSPORT to fetch missing base-chain state.

- `client` (CLIENT)

Execution CLIENT. Returns a CLIENT for retained execution state. Attach a TRANSPORT to fetch missing base-chain state.

## Overload 4: client(UUID, UBIGINT)

```sql
client(UUID, UBIGINT)
```

Restores retained execution state only when its lineage matches expected_chain_id.

- Kind: scalar
- Execution context: Offline
- Behavior: Execution Client Constructor
- Execution modes: Execution Client
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `execution_id` (UUID; required; positional) — UUID for retained execution state in Determica's local catalog.
- `expected_chain_id` (UBIGINT; required; positional) — Required EVM chain id. Restoration fails when the execution lineage belongs to another chain.

### Returns

Execution CLIENT

Returns a CLIENT for retained execution state. Attach a TRANSPORT to fetch missing base-chain state.

- `client` (CLIENT)

Execution CLIENT. Returns a CLIENT for retained execution state. Attach a TRANSPORT to fetch missing base-chain state.

## Guidance

### CLIENT state modes

A CLIENT identifies the state for a read. Its durable identity does not include TRANSPORT credentials or request policy. Determica uses those only to fetch missing state.

- A live CLIENT follows the selected chain until it is pinned.
- A pinned CLIENT identifies one block. attach_transport lets it fetch missing state.
- An execution CLIENT identifies retained simulation state. An attached TRANSPORT can fetch missing chain state.
- Call client_context to inspect the state identity and whether a TRANSPORT is attached.

### Chain validation

Use an expected_chain_id overload when the function must reject state from another chain.

- The function compares expected_chain_id with trusted TRANSPORT metadata or retained execution lineage. It does not send an RPC request.
- This check does not pin a live CLIENT. Call pin when later reads must use the same block.

## Additional examples

```sql
SELECT client($transport) AS client;
```
