Skip to content

Simulate

The types of Eth.simulateV1: a payload says which calls to run in which made-up blocks, and the result is those blocks with the outcome of each call.

import { Effect } from "effect";
import { Address } from "@ethect/core";
import { Eth, type Simulate } from "@ethect/core/rpc";
const FROM = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
const TO = Address.makeUnsafe("0x70997970C51812dc3A010C7d01b50e0d17dc79C8");
const outcome = Effect.gen(function* () {
const payload: Simulate.Payload = {
blockStateCalls: [
{
blockOverrides: { time: 2_000_000_000n },
calls: [{ from: FROM, to: TO, value: 1n }],
},
],
};
const blocks: Simulate.Simulate = yield* Eth.simulateV1(payload, "latest");
const call: Simulate.Call | undefined = blocks[0]?.calls[0];
return call?.status; // "success"
});
Schema Type Describes Used by
Simulate.payloadSchema Simulate.Payload what to simulate, for blocks with their transactions as hashes the first param of Eth.simulateV1
Simulate.fullPayloadSchema Simulate.FullPayload the same with returnFullTransactions: true the first param of Eth.simulateV1
Simulate.schema Simulate.Simulate the simulated blocks, with transactions as hashes the result for a Simulate.Payload
Simulate.fullSchema Simulate.Full the simulated blocks, with transactions in full the result for a Simulate.FullPayload
Simulate.callSchema Simulate.Call the outcome of one call the calls of a simulated block

Simulate.Payload and Simulate.FullPayload.

Field Type Notes
blockStateCalls ReadonlyArray of blocks the blocks to simulate, in order
traceTransfers boolean (optional) report transfers of ether as ERC-20 Transfer logs
validation boolean (optional) check nonces, balances and fees as a real block would
returnFullTransactions false (optional) in Simulate.Payload
returnFullTransactions true in Simulate.FullPayload return the transactions of each block in full

Each entry of blockStateCalls is one block. Its three fields are optional.

Field Type Notes
blockOverrides BlockOverride header fields of the simulated block
stateOverrides StateOverride state changed before the calls of the block run
calls ReadonlyArray<TransactionRequest> the calls of the block, in order

Simulate.Call, the outcome of one call.

Field Type Notes
status "success" | "failure"
returnData Hex what the call returned, "0x" for nothing
gasUsed bigint
maxUsedGas bigint (optional) the most gas the call held at once, before refunds. anvil 1.9 sends it.
logs ReadonlyArray<Log> (optional) the logs the call emitted
error { code: number, message: string, data?: unknown } (optional) on a failed call: the JSON-RPC error a real call would fail with

An entry of Simulate.Simulate has every field of a Block.Block, plus calls. An entry of Simulate.Full has every field of a Block.Full, plus calls.

Field Type Notes
calls ReadonlyArray<Simulate.Call> one per call of the block, in order
transactions ReadonlyArray<Hash> in Simulate.Simulate the simulated transactions, one per call
transactions ReadonlyArray<Transaction> in Simulate.Full
  • The payload chooses the result. Eth.simulateV1 is an overload: a payload with returnFullTransactions: true gives a Simulate.Full, any other gives a Simulate.Simulate.
  • A failed call is a value. It has the status "failure" and an error. A revert has the code 3 and its revert data in error.data.
  • status is a name. The node answers "0x1" or "0x0", decoded to "success" or "failure". A Receipt says "reverted" where a simulated call says "failure".
  • error is the node’s error object. It is not an RpcError and has no reason. Pass it to RpcError.fromWire to classify it: a revert gives ExecutionReverted with its data.
  • Simulated transactions are not signed. In a Simulate.Full, anvil fills the signature fields of a transaction with placeholders.