BlockId
How a call names the block it is about: a block number, a tag such as "latest", or an object
that names the block by number or by hash (EIP-1898).
import { Effect } from "effect";import { Address } from "@ethect/core";import { Eth } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
const balances = Effect.all([ Eth.getBalance(ADDRESS, 19_000_000n), Eth.getBalance(ADDRESS, "finalized"), Eth.getBalance(ADDRESS, { blockHash: `0x${"ab".repeat(32)}` }),]);Schemas
Section titled “Schemas”| Schema | Type | Describes | Used by |
|---|---|---|---|
BlockId.tagSchema |
BlockId.Tag |
one of the five tags | the two schemas below |
BlockId.numberOrTagSchema |
BlockId.NumberOrTag |
a block number or a tag | Eth.getBlockByNumber and the other methods named …ByNumber or …ByBlockNumber…, Eth.feeHistory, fromBlock and toBlock of a Filter |
BlockId.schema |
BlockId.BlockId |
a block number, a tag, or an object naming the block by number or by hash | Eth.getBalance and the other state methods, Eth.call, Eth.estimateGas, Eth.getBlockReceipts |
Import a type to name it in your own signatures.
import { Address } from "@ethect/core";import { type BlockId, Eth } from "@ethect/core/rpc";
const balanceAt = (address: Address.Address, block: BlockId.BlockId) => Eth.getBalance(address, block);What you write, and what the node receives for it.
| You write | Sent as | Names |
|---|---|---|
19_000_000n |
"0x121eac0" |
the block with that number |
"latest" |
"latest" |
a block by tag |
{ blockNumber: 1n } |
{"blockNumber":"0x1"} |
the block with that number, in the object form |
{ blockHash } |
{"blockHash":"0x…"} |
the block with that hash |
{ blockHash, requireCanonical: true } |
{"blockHash":"0x…","requireCanonical":true} |
the same, refused when that block is not on the canonical chain |
BlockId.NumberOrTag covers the first two rows. BlockId.BlockId covers all five.
BlockId.Tag is one of five strings.
| Tag | Names |
|---|---|
"latest" |
the most recent block of the chain |
"earliest" |
the oldest block the node has: the genesis block, unless the node pruned its history |
"pending" |
the block the node is building from its pool |
"safe" |
the most recent block the consensus layer holds as safe |
"finalized" |
the most recent finalized block |
Behavior
Section titled “Behavior”- A number is a
bigint.19_000_000n, not19_000_000: a plainnumberis a type error. A negative one fails with aCodecErroron the params, and nothing is sent. - Left out means not sent. Where a method marks its block optional, there is no default: see Naming a block.
- A hash pins the block. After a reorg
"latest"and a number can name another block. An object withblockHashcannot. …ByNumbermethods take no object. A method typed withBlockId.NumberOrTagrefuses{ blockHash }at compile time. Its sibling named…ByHashtakes the hash.- A block the node does not have. What happens depends on the method. A block lookup
returns
null. On anvil 1.9 a state method fails with anRpcError: reasonInvalidParamsfor a number above the head,ResourceNotFoundfor an unknownblockHash.