# Node

The three methods about the test node itself: how it is set up, what identifies it, and whether
it logs the requests it gets.

| Method | JSON-RPC | Returns | Description |
| --- | --- | --- | --- |
| [`nodeInfo`](#nodeinfo) | `anvil_nodeInfo` | `NodeInfo` | How the node is set up: its head, hard fork and fees, and the endpoint it forks. |
| [`metadata`](#metadata) | `anvil_metadata` | `NodeMetadata` | What identifies the node: its version, chain and head, its fork, its snapshots. |
| [`setLoggingEnabled`](#setloggingenabled) | `anvil_setLoggingEnabled` | `null` | Turns the node's logging of requests on or off. |

Each returns an [`Effect<…, Method.Error, Transport>`](https://ethect.dev/rpc/method/#calling-a-method).

## nodeInfo

Returns how the node is set up: its head, its hard fork, its fees and the endpoint it forks, if
any.

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

const setup = Effect.gen(function* () {
  const info = yield* Anvil.nodeInfo();
  return {
    hardFork: info.hardFork, // "Bpo1"
    chainId: info.environment.chainId, // 31337
    baseFee: info.environment.baseFee, // 1000000000n
    forked: info.forkConfig.forkUrl !== null, // false
  };
});
```

- **JSON-RPC:** `anvil_nodeInfo`
- **Parameters:** none.
- **Returns:** [`NodeInfo`](https://ethect.dev/rpc/types/node-info/).

## metadata

Returns what identifies the node: its version, its chain and head, where it was forked from and
the snapshots it holds.

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

const identity = Effect.gen(function* () {
  const metadata = yield* Anvil.metadata();
  return {
    client: metadata.clientVersion, // "anvil/v1.9.0"
    chainId: metadata.chainId, // 31337
    head: metadata.latestBlockNumber, // 0n
    forked: metadata.forkedNetwork !== null, // false
  };
});
```

- **JSON-RPC:** `anvil_metadata`
- **Parameters:** none.
- **Returns:** [`NodeMetadata`](https://ethect.dev/rpc/types/node-metadata/).

## setLoggingEnabled

Turns the node's logging of the requests it gets on or off.

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

const quiet = Effect.gen(function* () {
  yield* Anvil.setLoggingEnabled(false);
});
```

- **JSON-RPC:** `anvil_setLoggingEnabled`
- **Parameters:** `enabled` (`boolean`).
- **Returns:** `null`.
- The log is what the anvil process prints. Nothing about it can be read back over JSON-RPC.

## Behavior

- **Two views of the head.** `nodeInfo` gives the head as `currentBlockNumber` and `metadata`
  as `latestBlockNumber`. Both are `bigint`s.
- **Fork fields are `null` off a fork.** `forkConfig` always has its three keys, each `null`
  unless the node is a fork, and `forkedNetwork` is `null` as a whole. See
  [`Anvil.reset`](https://ethect.dev/rpc/anvil/fork/#reset).
