# `X402.Facilitator.PendingSettlementStore.ETS`
[🔗](https://github.com/cardotrejos/x402/blob/v0.9.0/lib/x402/facilitator/pending_settlement_store/ets.ex#L1)

ETS-backed pending-settlement store adapter.

Entries expire after `:ttl_ms` (default: 5 minutes, matching the reference
SDKs' pending-settlement TTL). Expired entries are removed by an internal
periodic cleanup loop.

> #### Per-node only {: .warning}
>
> The ETS table lives on the local node. A facilitator running more than
> one instance behind a load balancer must supply a shared-store adapter
> instead — a retried settlement routed to a different node would miss this
> table and re-broadcast. See the adapter sketch in
> `X402.Facilitator.PendingSettlementStore`.

## Usage

Add the store to your supervision tree and pass it to the engine:

    children = [
      {X402.Facilitator.PendingSettlementStore.ETS, name: MyApp.PendingStore}
    ]

    {:ok, engine} =
      X402.Facilitator.Engine.new(
        rpc: rpc,
        signer: signer,
        networks: ["eip155:84532"],
        pending_settlement_store:
          {X402.Facilitator.PendingSettlementStore.ETS, MyApp.PendingStore}
      )

# `server`

```elixir
@type server() :: GenServer.server()
```

Server identifier accepted by `GenServer.call/3`.

# `child_spec`
*since 0.6.0* 

```elixir
@spec child_spec(keyword()) :: Supervisor.child_spec()
```

Returns a child specification for `X402.Facilitator.PendingSettlementStore.ETS`.

# `delete`
*since 0.6.0* 

```elixir
@spec delete(server(), X402.Facilitator.PendingSettlementStore.key()) ::
  X402.Facilitator.PendingSettlementStore.write_result()
```

Deletes a pending settlement entry.

# `get`
*since 0.6.0* 

```elixir
@spec get(server(), X402.Facilitator.PendingSettlementStore.key()) ::
  X402.Facilitator.PendingSettlementStore.get_result()
```

Looks up a pending settlement by key.

# `put`
*since 0.6.0* 

```elixir
@spec put(
  server(),
  X402.Facilitator.PendingSettlementStore.key(),
  X402.Facilitator.PendingSettlementStore.entry()
) :: X402.Facilitator.PendingSettlementStore.write_result()
```

Stores a pending settlement entry, resetting its TTL.

When the table is at `:max_size` and purging expired entries does not free
a slot, returns `{:error, :store_full}` rather than evicting a live entry —
evicting a live pending record would silently turn its retry into a second
broadcast attempt. The engine treats a failed put as "could not persist for
retry" and reports the settlement accordingly.

# `start_link`
*since 0.6.0* 

```elixir
@spec start_link(keyword()) ::
  GenServer.on_start() | {:error, NimbleOptions.ValidationError.t()}
```

Starts an ETS-backed pending-settlement store process.

## Options

* `:name` (`t:term/0`) - Registered name for the store process. The default value is `X402.Facilitator.PendingSettlementStore.ETS`.

* `:ttl_ms` (`t:non_neg_integer/0`) - Time-to-live for entries in milliseconds. The default value is `300000`.

* `:cleanup_interval_ms` (`t:pos_integer/0`) - How often expired entries are cleaned up, in milliseconds. The default value is `60000`.

* `:max_size` (`t:pos_integer/0`) - Maximum number of entries in the store. The default value is `10000`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
