Skip to content

The debug_ methods (Debug)

The debug_ namespace: blocks, transactions and receipts in their encoded form, and executions traced with geth’s tracers.

import { Effect } from "effect";
import { FetchHttpClient } from "effect/http";
import { Transport } from "@ethect/core";
import { Debug, Eth } from "@ethect/core/rpc";
const program = Effect.gen(function* () {
const [from, to] = yield* Eth.accounts();
const receipt = yield* Eth.sendTransactionSync({ from, to, value: 1n });
const frame = yield* Debug.traceTransaction(receipt.transactionHash, {
tracer: "callTracer",
});
return { type: frame.type, value: frame.value, gasUsed: frame.gasUsed };
});
const traced = await program.pipe(
Effect.provide(Transport.http("http://127.0.0.1:8545")),
Effect.provide(FetchHttpClient.layer),
Effect.runPromise,
);
// { type: "CALL", value: 1n, gasUsed: 21000n }

A method takes its JSON-RPC params in order and returns an Effect of the decoded result. The name is the wire name without its prefix: debug_traceCall is Debug.traceCall.

The namespace comes from geth. anvil 1.9 serves every method on these pages except getBadBlocks and getRawBlockAccessList, so a local test node is where to try them: see Testing.

Method JSON-RPC Returns Description
getRawHeader debug_getRawHeader Hex A block header, RLP-encoded.
getRawBlock debug_getRawBlock Hex A block, RLP-encoded.
getRawTransaction debug_getRawTransaction Hex | null A transaction in its signed, encoded form, by hash.
getRawTransactions debug_getRawTransactions Hex[] The transactions of a block, each in its signed, encoded form.
getRawReceipts debug_getRawReceipts Hex[] The receipts of a block, each in its encoded form.
getRawBlockAccessList debug_getRawBlockAccessList Hex What a block read and wrote, RLP-encoded (EIP-7928).
getBadBlocks debug_getBadBlocks bad blocks The invalid blocks the node saw on the network lately.
Method JSON-RPC Returns Description
traceTransaction debug_traceTransaction a trace Runs a mined transaction again and traces it.
traceCall debug_traceCall a trace Runs a call without sending a transaction and traces it.
traceBlockByNumber debug_traceBlockByNumber a trace per transaction Runs a block again and traces each of its transactions, by block number or tag.
traceBlockByHash debug_traceBlockByHash a trace per transaction The same, by block hash.
traceBlock debug_traceBlock a trace per transaction The same, for an RLP-encoded block.

The last argument of a tracing method is its options. They select the tracer, and the tracer decides the type of the trace.

Options Tracer Trace
no tracer the struct logger StructLog.Trace: one log per opcode
tracer: "callTracer" callTracer CallFrame.CallFrame: the tree of calls
tracer: "prestateTracer" prestateTracer Prestate.Prestate: the accounts touched, as they were before
the same with tracerConfig: { diffMode: true } prestateTracer, diff mode Prestate.Diff: the accounts changed, before and after
tracer: "4byteTracer" 4byteTracer Trace.FourByte: calls per function selector
tracer: "noopTracer" noopTracer an empty object
any other tracer a custom tracer unknown
import { Debug } from "@ethect/core/rpc";
import type { Hash } from "@ethect/core";
const traces = (hash: Hash.Hash) => ({
// Effect<StructLog.Trace, …>
opcodes: Debug.traceTransaction(hash),
// Effect<CallFrame.CallFrame, …>
calls: Debug.traceTransaction(hash, { tracer: "callTracer" }),
// Effect<Prestate.Prestate, …>
state: Debug.traceTransaction(hash, { tracer: "prestateTracer" }),
});

The five tracing methods take the same options and are typed the same way. The methods that trace a block return one entry per transaction, each holding the trace of the tracer.