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 |
eth_coinbase |
Address |
The address that receives the node’s block rewards. |
protocolVersion |
eth_protocolVersion |
number |
The version of the eth wire protocol. |
config |
eth_config |
ChainConfig |
The fork configuration: current, next and last. |
capabilities |
eth_capabilities |
Capabilities |
What history the node keeps. |
None of them takes a parameter, and each returns an
Effect 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, Eth.blockNumber
and Eth.syncing.
coinbase
Section titled “coinbase”Returns the address that receives the rewards of the blocks the node produces.
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, in lowercase. anvil answers the zero address untilAnvil.setCoinbasegives it another.
protocolVersion
Section titled “protocolVersion”Returns the version of the eth wire protocol the node speaks with its peers.
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 samenumber. - Not served by every client.
config
Section titled “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.
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. Each ofcurrent,nextandlastisnullwhen the node has no such fork to report.
capabilities
Section titled “capabilities”Returns the node’s head and, for each kind of data, whether the node serves it and from which block.
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. - anvil 1.9 does not serve it: the call fails with an
RpcErrorwhose reason isMethodNotFound.
Behavior
Section titled “Behavior”- Not every node serves all four. A method the node does not know fails with an
RpcErrorwhose reason isMethodNotFound. Recover from it withEffect.catchReason("RpcError", "MethodNotFound", …), as the example above does. - Nothing is cached. Each call is a request. Keep the result when you need it often.