# Node information

Four methods that describe the node itself: its fee recipient, its wire protocol version, the
forks it runs and the history it keeps.

| Method | JSON-RPC | Returns | Description |
| --- | --- | --- | --- |
| [`coinbase`](#coinbase) | `eth_coinbase` | `Address` | The address that receives the node's block rewards. |
| [`protocolVersion`](#protocolversion) | `eth_protocolVersion` | `number` | The version of the `eth` wire protocol. |
| [`config`](#config) | `eth_config` | `ChainConfig` | The fork configuration: current, next and last. |
| [`capabilities`](#capabilities) | `eth_capabilities` | `Capabilities` | What history the node keeps. |

None of them takes a parameter, and each returns an
[`Effect`](https://ethect.dev/rpc/method/#calling-a-method) of the type in the table, which fails with a
`Method.Error` and needs a `Transport`. For the chain id, the head and the sync status, see
[`Eth.chainId`](https://ethect.dev/rpc/eth/chain-id/), [`Eth.blockNumber`](https://ethect.dev/rpc/eth/block-number/)
and [`Eth.syncing`](https://ethect.dev/rpc/eth/syncing/).

## coinbase

Returns the address that receives the rewards of the blocks the node produces.

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

const feeRecipient = Eth.coinbase().pipe(
  Effect.map((address) => Address.checksum(address)),
);
```

- **JSON-RPC:** `eth_coinbase`
- **Parameters:** none.
- **Returns:** [`Address.Address`](https://ethect.dev/reference/primitives/address/), in lowercase. anvil answers
  the zero address until [`Anvil.setCoinbase`](https://ethect.dev/rpc/anvil/chain/#setcoinbase) gives it
  another.

## protocolVersion

Returns the version of the `eth` wire protocol the node speaks with its peers.

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

const version = Eth.protocolVersion().pipe(
  Effect.map((version) => `eth/${version}`),
);
```

- **JSON-RPC:** `eth_protocolVersion`
- **Parameters:** none.
- **Returns:** `number`. A node sends it as a hex quantity, and anvil as a JSON number: both
  decode to the same `number`.
- Not served by every client.

## config

Returns the fork configuration of the node, as defined by EIP-7910: the fork in effect, the
next one scheduled and the last one it knows.

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

const forks = Effect.gen(function* () {
  const { current, next } = yield* Eth.config();
  return {
    chainId: current?.chainId, // 31337
    maxBlobs: current?.blobSchedule?.max, // 15
    nextForkAt: next?.activationTime, // undefined: no fork is scheduled
  };
});
```

- **JSON-RPC:** `eth_config`
- **Parameters:** none.
- **Returns:** [`ChainConfig.ChainConfig`](https://ethect.dev/rpc/types/chain-config/). Each of `current`,
  `next` and `last` is `null` when the node has no such fork to report.

## capabilities

Returns the node's 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 oldestLogs = Eth.capabilities().pipe(
  // the oldest block the node has logs for, or null when it serves no logs
  Effect.map(({ logs }) => (logs.disabled ? null : logs.oldestBlock)),
  // a node that does not serve the method
  Effect.catchReason("RpcError", "MethodNotFound", () => Effect.succeed(null)),
);
```

- **JSON-RPC:** `eth_capabilities`
- **Parameters:** none.
- **Returns:** [`Capabilities.Capabilities`](https://ethect.dev/rpc/types/capabilities/).
- anvil 1.9 does not serve it: the call fails with an `RpcError` whose reason is
  `MethodNotFound`.

## Behavior

- **Not every node serves all four.** A method the node does not know fails with an `RpcError`
  whose reason is `MethodNotFound`. Recover from it with
  `Effect.catchReason("RpcError", "MethodNotFound", …)`, as the example above does.
- **Nothing is cached.** Each call is a request. Keep the result when you need it often.
