# Capabilities

What history a node keeps, as `eth_capabilities` returns it: its head and, for each kind of
data, whether the node serves it and from which block.

```ts
import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";

const servesReceiptsOf = (block: bigint) =>
  Eth.capabilities().pipe(
    // capabilities: Capabilities.Capabilities
    Effect.map(({ receipts }) =>
      receipts.disabled || receipts.oldestBlock === undefined
        ? false
        : receipts.oldestBlock <= block,
    ),
  );
```

It lets a program send a query to a node that can answer it, instead of finding out from an
error.

## Schemas

| Schema | Type | Describes | Returned by |
| --- | --- | --- | --- |
| `Capabilities.schema` | `Capabilities.Capabilities` | the head and the retention of each kind of data | [`Eth.capabilities`](https://ethect.dev/rpc/eth/node/#capabilities) |
| `Capabilities.resourceSchema` | `Capabilities.Resource` | whether one kind of data is served, from which block, and how old data is dropped | each of the six kinds of a `Capabilities.Capabilities` |

## Fields

`Capabilities.Capabilities`.

| Field | Type | Notes |
| --- | --- | --- |
| `head` | `{ number: bigint; hash: Hash }` | the node's most recent block |
| `state` | `Capabilities.Resource` | |
| `tx` | `Capabilities.Resource` | |
| `logs` | `Capabilities.Resource` | |
| `receipts` | `Capabilities.Resource` | |
| `blocks` | `Capabilities.Resource` | |
| `stateproofs` | `Capabilities.Resource` | |

## Resource fields

`Capabilities.Resource`.

| Field | Type | Notes |
| --- | --- | --- |
| `disabled` | `boolean` | `true` when the node does not serve this kind of data |
| `oldestBlock` | `bigint` (optional) | the oldest block the node has this data for |
| `deleteStrategy` | `{ type: string; retentionBlocks?: bigint }` (optional) | how the node drops old data |

## On the wire

An answer recorded from the test suite of the Ethereum execution APIs.

```json
{
  "head": {
    "number": "0x3c",
    "hash": "0x52bccfc9c4d4874b1898c0fbd0ae3b598a0edc7b94d9b796857dbbe1093c32e0"
  },
  "state": { "disabled": false, "oldestBlock": "0x0" },
  "tx": { "disabled": false, "oldestBlock": "0x0" },
  "logs": {
    "disabled": false,
    "oldestBlock": "0x0",
    "deleteStrategy": { "type": "window", "retentionBlocks": "0x23dbb0" }
  },
  "receipts": { "disabled": false, "oldestBlock": "0x0" },
  "blocks": { "disabled": false, "oldestBlock": "0x0" },
  "stateproofs": { "disabled": false, "oldestBlock": "0x0" }
}
```

Decoded, `head.number` is `60n` and `logs.deleteStrategy.retentionBlocks` is `2350000n`.

## Behavior

- **Optional means absent.** `oldestBlock` and `deleteStrategy` are left out of the object when
  the node does not send them. Test them with `!== undefined`.
- **Block numbers are `bigint`.** `head.number`, `oldestBlock` and `retentionBlocks` are sent
  as quantities. See [values on the wire](https://ethect.dev/rpc/guides/values/).
- **Not served by anvil.** anvil 1.9 does not know `eth_capabilities`: the call fails with an
  `RpcError` whose reason is `MethodNotFound`.
