Prestate
The result of the prestateTracer: the accounts an execution touched as they were before it
and, in diff mode, what became of the ones it changed.
import { Effect } from "effect";import { Debug } from "@ethect/core/rpc";import type { Address, Hash } from "@ethect/core";
const balanceBefore = (hash: Hash.Hash, account: Address.Address) => Debug.traceTransaction(hash, { tracer: "prestateTracer" }).pipe( // prestate: Prestate.Prestate Effect.map((prestate) => prestate[account]?.balance ?? 0n), );Schemas
Section titled “Schemas”| Schema | Type | Describes | Used by |
|---|---|---|---|
Prestate.schema |
Prestate.Prestate |
the accounts touched, by address | the result of a Debug.trace* call with tracer: "prestateTracer" |
Prestate.diffSchema |
Prestate.Diff |
the accounts changed, before and after | the result of the same call in diff mode |
Prestate.accountSchema |
Prestate.Account |
the state of one account | each value of a Prestate |
Prestate.configSchema |
Prestate.Config |
the settings of the tracer | the tracerConfig of the call |
Prestate.diffConfigSchema |
Prestate.DiffConfig |
the settings of diff mode | the tracerConfig that asks for a Diff |
Prestate
Section titled “Prestate”Prestate.Prestate is a record: Record<Hex, Prestate.Account>. A key is the address of an
account, in lowercase, and an Address.Address indexes it
directly.
Account fields
Section titled “Account fields”Prestate.Account.
| Field | Type | Notes |
|---|---|---|
balance |
bigint (optional) |
in wei |
nonce |
number (optional) |
|
code |
Hex (optional) |
the code of a contract |
codeHash |
Hash (optional) |
|
storage |
Record<Hash, Hash> (optional) |
the slots the execution read or wrote, by slot |
Diff fields
Section titled “Diff fields”Prestate.Diff, the result in diff mode.
| Field | Type | Notes |
|---|---|---|
pre |
Prestate.Prestate |
the accounts the execution changed, as they were before it |
post |
Prestate.Prestate |
the same accounts after it, with only the fields that changed |
import { Effect } from "effect";import { Debug } from "@ethect/core/rpc";import type { Address, Hash } from "@ethect/core";
const nonces = (hash: Hash.Hash, sender: Address.Address) => Debug.traceTransaction(hash, { tracer: "prestateTracer", tracerConfig: { diffMode: true }, }).pipe( // diff: Prestate.Diff Effect.map((diff) => [diff.pre[sender]?.nonce, diff.post[sender]?.nonce]), // for instance [1, 2] );Config fields
Section titled “Config fields”Prestate.Config and Prestate.DiffConfig, passed as tracerConfig. They differ by
diffMode alone.
| Field | Type | Notes |
|---|---|---|
diffMode |
false (optional) in Config, true in DiffConfig |
true asks for a Diff |
disableCode |
boolean (optional) |
leave the code out of every account |
disableStorage |
boolean (optional) |
leave the storage out of every account |
Behavior
Section titled “Behavior”- A field is absent when it is empty. An account without code has no
code, and one that never sent a transaction has nononce. Read a field with a default:account.nonce ?? 0. - In
post, absent means unchanged. Thepostof an account holds only what the execution changed. A contract whose storage alone changed has astorageand nothing else. - Created and destroyed accounts. An account the execution created is only in
post. One it destroyed is only inpre. - Storage holds what was touched, not everything. In a
Prestate, a slot the execution read or wrote is there with the value it had before. The other slots of the contract are not. diffModeselects the type.diffMode: truegives aDiff. Left out orfalse, the result is aPrestate: see Tracers.- More than the two parties. The fee recipient of the block is among the accounts touched, with the sender and the account called.