# attach_transport

Attaches transport authority to a pinned or execution CLIENT so missing state can be fetched without changing the CLIENT's durable state identity.

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

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

Attaches transport authority to a pinned or execution CLIENT so missing state can be fetched without changing the CLIENT's durable state identity.

## Overload 1: attach_transport(CLIENT, TRANSPORT)

```sql
attach_transport(CLIENT, TRANSPORT)
```

Checks the TRANSPORT against the CLIENT lineage and returns a new CLIENT that can fetch missing state.

- Kind: scalar
- Execution context: Offline
- Behavior: Attach
- Execution modes: Live Client, Pinned Client, 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: durable_state_write

### Requirements

- client_state_context

### Inputs

- `client` (CLIENT; required; positional) — Pinned or execution CLIENT whose durable state identity the function preserves.
- `transport` (TRANSPORT; required; positional) — TRANSPORT used to fetch chain state missing from local retained state.

### Returns

Hydrated CLIENT

Returns a new CLIENT with the TRANSPORT attached. The function does not modify the input CLIENT.

- `client` (CLIENT)

Hydrated CLIENT. Returns a new CLIENT with the TRANSPORT attached. The function does not modify the input CLIENT.

## Guidance

### Transport does not change identity

attach_transport lets a CLIENT fetch missing state. It does not change the chain, block, or execution state that the CLIENT identifies.

- The function does not modify the source CLIENT.
- The TRANSPORT's trusted declared chain id must match the CLIENT lineage. For a pinned CLIENT, the function also validates the pinned header against the provider.
- Store credentials in runtime TRANSPORT configuration. The durable CLIENT identity does not include them.

## Additional examples

```sql
WITH execution AS MATERIALIZED (
  -- Materialize run() to make its execution visible to client(execution_id).
  SELECT execution_id
  FROM run((SELECT
    -- Pin the CLIENT so this simulation uses one block.
    pin(client($transport), 'finalized') AS client,
    'attach-transport-example' AS candidate_key,
    program([
      -- Use the identity precompile for a minimal successful program.
      execute_call(
        '0x00'::ADDRESS,
        '0x04'::ADDRESS,
        '0x'::BYTES,
        0::UINT256,
        50000
      )
    ]) AS program
  ))
)
-- Attach the TRANSPORT to the retained execution CLIENT.
SELECT attach_transport(client(execution_id), $transport) AS client
FROM execution;
```
