Raw data
The seven methods that return chain data in its encoded form: a header, a block, transactions, receipts and a block access list as the bytes a node stores and hashes.
| 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. |
Each returns an Effect<…, Method.Error, Transport>.
The methods about a block take a BlockId: a number, a tag or an
object that names the block by hash. The param is required.
ethect has no RLP decoder: the bytes are returned as Hex, for
you to hash, compare or hand to another tool.
getRawHeader
Section titled “getRawHeader”Returns the header of a block, RLP-encoded. Its Keccak-256 hash is the hash of the block.
import { Effect } from "effect";import { Hash, Hex } from "@ethect/core";import { Debug } from "@ethect/core/rpc";
const blockHash = Effect.gen(function* () { const header = yield* Debug.getRawHeader("latest"); const bytes = yield* Hex.toBytes(header); return Hash.keccak256(bytes); // the `hash` of the latest block});- JSON-RPC:
debug_getRawHeader - Parameters:
block(BlockId.BlockId). - Returns:
Hex.Hex. - For a block it does not have, anvil 1.9 fails the call with an
RpcErrorof reasonResourceNotFound.
getRawBlock
Section titled “getRawBlock”Returns a block, RLP-encoded: its header, its transactions and the rest of its body.
import { Effect } from "effect";import { Hex } from "@ethect/core";import { Debug, Eth } from "@ethect/core/rpc";
const sizes = Effect.gen(function* () { const raw = yield* Debug.getRawBlock("latest"); const block = yield* Eth.getBlockByNumber("latest", false); return { bytes: Hex.size(raw), size: block?.size }; // the same number});- JSON-RPC:
debug_getRawBlock - Parameters:
block(BlockId.BlockId). - Returns:
Hex.Hex. It is whatDebug.traceBlocktakes. - For a block it does not have, anvil 1.9 fails the call with an
RpcErrorof reasonResourceNotFound.
getRawTransaction
Section titled “getRawTransaction”Returns a transaction in its signed, encoded form, by hash.
import { Debug } from "@ethect/core/rpc";import type { Hash } from "@ethect/core";
// "0x02f8…" for an EIP-1559 transaction, or nullconst raw = (hash: Hash.Hash) => Debug.getRawTransaction(hash);- JSON-RPC:
debug_getRawTransaction - Parameters:
hash(Hash). - Returns:
Hex | null.nullwhen the node knows no transaction with that hash. A transaction still in the pool is returned too. - It is the value
Eth.getRawTransactionByHashreturns, and whatEth.sendRawTransactiontakes.
getRawTransactions
Section titled “getRawTransactions”Returns the transactions of a block, each in its signed, encoded form.
import { Effect } from "effect";import { Debug } from "@ethect/core/rpc";
const count = Debug.getRawTransactions("latest").pipe( Effect.map((transactions) => transactions.length),);- JSON-RPC:
debug_getRawTransactions - Parameters:
block(BlockId.BlockId). - Returns:
ReadonlyArray<Hex>, in the order of the block. Empty for a block without transactions. - Not served by every client.
- anvil 1.9 also answers an empty array for a block it does not have.
getRawReceipts
Section titled “getRawReceipts”Returns the receipts of a block, each in its encoded form.
import { Effect } from "effect";import { Debug } from "@ethect/core/rpc";
const types = Effect.gen(function* () { const receipts = yield* Debug.getRawReceipts("latest"); // a typed receipt starts with its type byte: "0x02" for EIP-1559 return receipts.map((receipt) => receipt.slice(0, 4));});- JSON-RPC:
debug_getRawReceipts - Parameters:
block(BlockId.BlockId). - Returns:
ReadonlyArray<Hex>, one per transaction of the block. - For a block number above the head, anvil 1.9 fails the call with an
RpcErrorof reasonInvalidParams.
getRawBlockAccessList
Section titled “getRawBlockAccessList”Returns what a block read and wrote, RLP-encoded (EIP-7928). The decoded form is
Eth.getBlockAccessList.
import { Effect } from "effect";import { Debug } from "@ethect/core/rpc";
const accessList = Debug.getRawBlockAccessList("latest").pipe( Effect.catchReason("RpcError", "MethodNotFound", () => Effect.succeed(null)),);- JSON-RPC:
debug_getRawBlockAccessList - Parameters:
block(BlockId.BlockId). - Returns:
Hex.Hex. - anvil 1.9 does not serve it: it answers
Method not found. The method was checked against a mock, not against a node.
getBadBlocks
Section titled “getBadBlocks”Returns the invalid blocks the node saw on the network lately, each decoded and RLP-encoded.
import { Effect } from "effect";import { Debug } from "@ethect/core/rpc";
const hashes = Debug.getBadBlocks().pipe( Effect.map((bad) => bad.map((entry) => entry.hash)),);- JSON-RPC:
debug_getBadBlocks - Parameters: none.
- Returns: an array of objects with three fields, described below.
- anvil 1.9 does not serve it: it answers
Method not found. The method was checked against a mock, not against a node.
| Field | Type | Description |
|---|---|---|
block |
Block.Full |
the block, with its transactions in full |
hash |
Hash |
the hash of the block |
rlp |
Hex.Hex |
the block, RLP-encoded |
Behavior
Section titled “Behavior”- The block param is required. Unlike the state methods of
Eth, these methods do not leave the block to the node. Pass"latest"for the head. - By hash too. A block can be named as
{ blockHash }. The header and the block anvil returns are then the ones the number gives. - A missing block is not reported the same way everywhere. On anvil 1.9,
getRawHeaderandgetRawBlockfail withResourceNotFound,getRawReceiptsfails withInvalidParams, andgetRawTransactionssucceeds with an empty array. - A method the node does not serve fails with an
RpcErrorof reasonMethodNotFound.