Skip to content

JSON-RPC layer

The low-level layer of ethect: one typed definition per JSON-RPC method and per subscription kind, in the namespaces nodes and wallets serve. It is the @ethect/core/rpc entry point.

import { Effect } from "effect";
import { Address } from "@ethect/core";
import { Eth } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
const account = Effect.gen(function* () {
const balance = yield* Eth.getBalance(ADDRESS, "latest"); // bigint
const nonce = yield* Eth.getTransactionCount(ADDRESS, "latest"); // number
return { balance, nonce };
});

A function of this layer is one request to a node: Eth.getBalance sends eth_getBalance and decodes its answer. Nothing is added, combined or retried.

Layer Entry point Holds Documented
The main APIs @ethect/core contracts, reads, transactions, events, wallets in the guides and under Reference
JSON-RPC @ethect/core/rpc a function per method, a stream per subscription kind, the wire types in this section
The base @ethect/core transports, errors, primitives under Reference
  • It is the layer underneath. The main APIs are built from these definitions: a read of a contract ends as Eth.call, a send as Eth.sendRawTransaction or Eth.sendTransaction. See How it works.
  • Most programs do not call it. Read and write a contract is where to start.
  • Call it for what the main APIs do not cover: a method of one client, a test node, exact control over one request.
Module Is Pages
Eth the 60 eth_ methods of an execution client, and the 5 subscription kinds state, blocks, transactions, logs, fees, sending
Wallet the 29 methods a wallet serves: wallet_, and the eth_ and personal_ ones that prompt the user accounts, chains, signing, call batches
Anvil, Evm the 51 anvil_ and 11 evm_ methods of a local test node state, mining, time, forks
Debug the 12 debug_ methods raw data and tracing
Txpool, Net, Web3 the 4 txpool_, 3 net_ and 2 web3_ methods one page each
Method, Subscription how a method and a subscription kind are defined defining your own
the wire types 38 modules, such as Block, Transaction, Receipt and Log: a schema and the type it decodes to one page each

That is 161 methods. Wallet shares 11 of its 29 with Eth.

import { type Block, Eth, Method, type Receipt, Wallet } from "@ethect/core/rpc";

Everything on these pages is imported from @ethect/core/rpc. Rolldown keeps the methods a program calls and drops the rest: see Installation.

A method returns an Effect that needs a transport, and fails with one of the three errors. Both come from @ethect/core, and they are the same whichever layer makes the call.

import { Effect } from "effect";
import { FetchHttpClient } from "effect/http";
import { Transport } from "@ethect/core";
import { Eth } from "@ethect/core/rpc";
const chainId = await Eth.chainId().pipe(
Effect.provide(Transport.http("http://127.0.0.1:8545")),
Effect.provide(FetchHttpClient.layer),
Effect.runPromise,
);
Guide Covers
Calling methods params in order, native results, naming a block, several calls
Batching several calls in one HTTP request
Subscriptions eth_subscribe as a Stream
Custom methods a method the library does not define, or one your chain shapes differently
Values on the wire how hex becomes bigint, number, addresses and names

The package’s tests run the definitions against anvil 1.9. A second, opt-in suite reads from a real node: the eth_ read methods (blocks, transactions, receipts, state, logs, fees, a call, a simulation) and a newHeads subscription. It makes a few dozen calls, sends nothing, and fails when an answer does not decode.

Client Chain
Geth 1.17 Ethereum mainnet, Hoodi
reth 2.11 Ethereum mainnet, Sepolia
Erigon 3.8 Ethereum mainnet
Nethermind 2.2 Gnosis
op-reth 2.8 OP Mainnet
reth 2.5, as Base runs it Base
Arbitrum nitro 3.13 Arbitrum One
zkSync Era zkSync Era
RskJ 9.0 Rootstock
bor 2.11 Polygon
BSC’s Geth BNB Smart Chain
Scroll’s Geth Scroll

What those nodes send differently is in the types: a null blob base fee on Arbitrum, a proof without codeHash on Scroll, forks that start at a block on Polygon. Each type page says so where it applies.

  • Not run: Besu. No public endpoint was found for it.
  • Not run: a real wallet. The Wallet methods are checked against their EIPs and a MockProvider, not against a wallet.
  • Not run: a browser. The tests run on Node.
  • Per method, the errors are anvil’s. A table that says “as anvil 1.9 reports them” was observed on anvil. Another client can answer the same mistake with another code.
  • Calling methods: the first guide of this layer.
  • Eth: every eth_ method, by group.
  • Types: the shape of what the methods take and return.
  • How it works: what a call does between your code and the node.