Eth.getProof
Returns the Merkle proof of an account and of the storage slots you name, as defined by EIP-1186.
import { Effect } from "effect";import { FetchHttpClient } from "effect/http";import { Address, Transport } from "@ethect/core";import { Eth } from "@ethect/core/rpc";
const slot0 = "0x0000000000000000000000000000000000000000000000000000000000000000";
const ADDRESS = Address.makeUnsafe("0x5FbDB2315678afecb367f032d93F642f64180aa3");
const program = Effect.gen(function* () { // a contract deployed on the local node, with 7 stored in slot 0 return yield* Eth.getProof(ADDRESS, [slot0], "latest");});
const proof = await program.pipe( Effect.provide(Transport.http("http://127.0.0.1:8545")), Effect.provide(FetchHttpClient.layer), Effect.runPromise,);// proof.nonce: 1// proof.balance: 0n// proof.storageProof[0].value: 7nThe call works over every transport. The examples below leave the transport out.
The account alone
Section titled “The account alone”Pass no slot to prove the account without any of its storage.
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 proof = yield* Eth.getProof(ADDRESS, [], "latest"); return { balance: proof.balance, nodes: proof.accountProof.length };});storageProof is then an empty array.
Against a block you trust
Section titled “Against a block you trust”A proof is checked against the state root of a block. Name that block by hash, so that the proof and the root belong together.
import { Effect } from "effect";import { Address } from "@ethect/core";import { Eth } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
const proven = Effect.gen(function* () { const block = yield* Eth.getBlockByNumber("finalized", false); if (block === null || block.hash === null) return null; const proof = yield* Eth.getProof(ADDRESS, [], { blockHash: block.hash }); return { stateRoot: block.stateRoot, proof };});Returns
Section titled “Returns”Effect<Proof.Proof, Method.Error, Transport>
A Proof: the account’s balance, nonce, code hash and storage
root, the trie nodes that prove them, and one storage proof per slot asked.
Parameters
Section titled “Parameters”address
Section titled “address”- Type:
Address.Address
The account to prove. A plain string is not accepted: build it with
Address.makeUnsafe, or with Address.make when it
comes from outside.
import { Address } from "@ethect/core";import { Eth } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
const proof = Eth.getProof(ADDRESS, [], "latest");- Type:
ReadonlyArray<Hex.Hex>
The storage slots to prove, as Hex. A slot may be written
short: "0x1" is sent as the 32-byte word of slot 1.
import { Address } from "@ethect/core";import { Eth } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0x5FbDB2315678afecb367f032d93F642f64180aa3");
const proof = Eth.getProof(ADDRESS, ["0x0", "0x1"], "latest");block (optional)
Section titled “block (optional)”- Type:
BlockId.BlockId
The block to prove against: a number, a tag ("latest", "earliest", "pending", "safe",
"finalized"), or an object that names the block by hash.
import { Effect } from "effect";import { Address } from "@ethect/core";import { Eth } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
const proofs = Effect.all([ Eth.getProof(ADDRESS, [], "finalized"), Eth.getProof(ADDRESS, [], 19_000_000n), Eth.getProof(ADDRESS, [], { blockHash: `0x${"ab".repeat(32)}` }),]);Behavior
Section titled “Behavior”- No default block. Left out, the param is not sent and the node chooses the block: see Naming a block.
- One storage proof per slot, in the order asked. Each has the slot as
key, itsvalueas abigint, and the trie nodes that prove it. - An account that does not exist has a proof too. Its balance is
0n, its nonce0, and each slot asked has the value0n. The proof shows the account is absent from the state. - Not verified. ethect returns the proof as the node sent it. Nothing in the library checks it against a state root yet.
Errors
Section titled “Errors”The three errors every method can fail with. The cases specific to this method, as anvil 1.9 reports them:
| Error | Reason | When |
|---|---|---|
RpcError |
InvalidParams |
the block number is above the chain’s head |
RpcError |
ResourceNotFound |
no block has the given blockHash |
CodecError |
on: "params" |
a slot is not hex or is longer than 32 bytes, or the block number is negative: nothing is sent |
JSON-RPC method
Section titled “JSON-RPC method”eth_getProof