Skip to content

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 anvil_nodeInfo NodeInfo How the node is set up: its head, hard fork and fees, and the endpoint it forks.
metadata anvil_metadata NodeMetadata What identifies the node: its version, chain and head, its fork, its snapshots.
setLoggingEnabled anvil_setLoggingEnabled null Turns the node’s logging of requests on or off.

Each returns an Effect<…, Method.Error, Transport>.

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

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.

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

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.

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

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.
  • Two views of the head. nodeInfo gives the head as currentBlockNumber and metadata as latestBlockNumber. Both are bigints.
  • 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.