Skip to content

NodeMetadata

What identifies a test node: its version, its chain and head, the chain it was forked from and the snapshots it holds.

import { Effect } from "effect";
import { Anvil } from "@ethect/core/rpc";
const snapshots = Effect.gen(function* () {
const id = yield* Anvil.snapshot();
const metadata = yield* Anvil.metadata();
// metadata: NodeMetadata.NodeMetadata
const taken = metadata.snapshots[id];
return taken === undefined ? "unknown snapshot" : `taken at block ${taken[0]}`;
// "taken at block 0"
});
Schema Type Describes Returned by
NodeMetadata.schema NodeMetadata.NodeMetadata the identity of a test node Anvil.metadata
Field Type Notes
clientVersion string the name and version of the client, as Web3.clientVersion returns it
clientSemver string (optional) the version alone, with its build
clientCommitSha string (optional) the commit the client was built from
chainId number
instanceId Hash an id of this run of the node
latestBlockNumber bigint the number of the head
latestBlockHash Hash the hash of the head
forkedNetwork an object, or null where the chain was forked from: see below. null when the node is not a fork.
snapshots Record<Hex, readonly [bigint, Hash]> by snapshot id, the number and the hash of the block it was taken at
Field Type Notes
chainId number the chain id of the forked chain
forkBlockNumber bigint the block it was forked at
forkBlockHash Hash the hash of that block

What anvil 1.9 answers when started without options:

{
"clientVersion": "anvil/v1.9.0",
"clientSemver": "1.9.0+6056c5845d.1793650614.dist",
"clientCommitSha": "6056c5845d34205a83cf7108042adb137325c9df",
"chainId": 31337,
"instanceId": "0x48ca7d3f018f99b1008ea8836704f1d9ad83e40ef3668e6c1e39e668ad80767b",
"latestBlockNumber": 0,
"latestBlockHash": "0x556ff4b89f7a003c8c90bc7363901efcc112ef515d5629825ee90a7cf0e84eed",
"forkedNetwork": null,
"snapshots": {}
}
  • Block numbers are bigints. anvil sends the block numbers of this object as JSON numbers. They decode to bigint, like the one Eth.blockNumber returns. Chain ids stay number.
  • snapshots lists what can be reverted to. An entry is added by Anvil.snapshot and removed when Anvil.revert spends it. A node without snapshots has an empty object.
  • Optional means absent. clientSemver and clientCommitSha are left out of the object when the node does not send them.
  • The setup is elsewhere. The hard fork, the fees and the fork endpoint are in NodeInfo.