Skip to content

Call.blockNumber

The state of the chain, as calls. Call.blockNumber, Call.timestamp, Call.chainId, Call.baseFee, Call.gasLimit, Call.balance and Call.blockHash are read like any call. Beside others, they are read inside the same eth_call, so they are of the same block.

import { Effect } from "effect";
import { FetchHttpClient } from "effect/http";
import { Address, Call, Erc20, Transport } from "@ethect/core";
const USDC = Address.makeUnsafe("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48");
const USER = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
const program = Effect.gen(function* () {
// alone: the plain method, here eth_blockNumber
const head = yield* Call.blockNumber;
// beside others: one eth_call. The ether, the tokens, the time and `block` are of one block
const position = yield* Call.all({
block: Call.blockNumber,
time: Call.timestamp,
ether: Call.balance(USER),
tokens: Erc20.at(USDC).balanceOf(USER),
});
return { head, ...position };
});
const state = await program.pipe(
Effect.provide(Transport.http("https://ethereum-rpc.publicnode.com")),
Effect.provide(FetchHttpClient.layer),
Effect.runPromise,
);

Each is a Call.View: an effect, a value for Call.all, and a call Call.read takes options for.

import { Call, type Address } from "@ethect/core";
const then = (user: Address.Address) => [
// what an account held at a past block
Call.read(Call.balance(user), { block: 19_000_000n }),
// the time of the last finalized block
Call.read(Call.timestamp, { block: "finalized" }),
];
Call Gives Read alone Read beside others, inside their eth_call
Call.blockNumber bigint eth_blockNumber Multicall3’s getBlockNumber(). On ArbOS, ArbSys.arbBlockNumber()
Call.timestamp bigint, in seconds the header of the block Multicall3’s getCurrentBlockTimestamp()
Call.chainId number eth_chainId, once per transport Multicall3’s getChainId()
Call.baseFee bigint, in wei per gas the header of the block Multicall3’s getBasefee(), in a call that offers a fee
Call.gasLimit bigint the header of the block Multicall3’s getCurrentBlockGasLimit()
Call.balance(account) bigint, in wei eth_getBalance Multicall3’s getEthBalance(account)
Call.blockHash(block) Hash.Hash the header of that block the contract of EIP-2935, then Multicall3’s getBlockHash(block)

“Beside others” is a Call.all, or reads issued separately that merged.

  • Beside others, a value comes from the execution that reads the rest. It is of their block by construction: nothing is asked before the call, and no block is named to it.
  • Alone, it is the plain method: one lighter request, for the same value.
  • Two values can need the node, each on few nodes, and each says so in its first lines below: the base fee and the hash of an old block.

Only a contract sees a stateOverride or a blockOverride. A state call read with one is therefore asked of a contract, with the override, and not of the plain method. It is the contract a group asks, so the value is the one a group gives and the node gives, as the override leaves it.

import { Call, type Address } from "@ethect/core";
// what the account would hold, were it given one ether
const funded = (user: Address.Address) =>
Call.read(Call.balance(user), {
stateOverride: { [user]: { balance: 10n ** 18n } },
});
Call Under an override, asked of
Call.balance, Call.timestamp, Call.gasLimit, Call.chainId its getter of Multicall3
Call.blockNumber Multicall3’s getter, and ArbSys on ArbOS. Also at a block named by its number, when the override is of the block: a contract may then see another
Call.baseFee Multicall3’s getter, in a call that offers a fee. The same override pays for it
Call.blockHash(block) the contract of EIP-2935 and blockhash, or ArbSys on ArbOS. A block neither holds is the node’s
  • Each call is a request of its own that carries the override: one for most, two for a hash.
  • The getter needs Multicall3 at that block. Where it is not deployed, the read fails with an AbiError: it returned no data.
  • from and gas alone change nothing of the chain. A read with only those keeps the plain method.

Call.View<bigint>

The number of the block the read is at. Beside others it is read inside their eth_call: it is the number of the block those reads ran at, and there is no request before it.

import { Effect } from "effect";
import { Call, type Address } from "@ethect/core";
// a balance, and the block to read the next ones from: one eth_call
const snapshot = (user: Address.Address) =>
Effect.map(
Call.all([Call.blockNumber, Call.balance(user)]),
([block, ether]) => ({ block, ether }),
);
  • It is the number the node knows the block by. On most chains that is what a contract sees, and Multicall3 is asked. On ArbOS, the system of Arbitrum One and of the chains built with it, a contract sees the number of an L1 block: there, ArbSys is asked, which says the number of its own.
  • Whether a chain is ArbOS is asked once per node, with an eth_getCode that leaves beside the first group, not before it. On ArbOS, that first group is asked a second time.
  • Only an answer of the node counts. While the node does not say whether there is code where ArbSys is, the read fails with why, and the node is asked again the next time: a number that could be the one of another chain is not given.
  • At a block named by its number, it is that number, and nothing is asked.
  • A chain that is neither, where a contract sees another number than the node gives and that has no ArbSys, gets what a contract sees. None is known to this library.

Call.View<bigint>

The time of the block, in seconds since 1970.

Call.View<number>

The id of the chain. Alone it is Transport.chainId: asked once per transport, and not at all under Transport.on.

Call.View<bigint>

The base fee of the block, in wei per gas. On a chain that has none, the read fails with a Revert.Unknown that has no data.

On two kinds of node it is a second request, because the call cannot be made to see it: a node that refuses state overrides, and zkSync Era, which answers the fee a call offers in place of the base fee. There the header of the block is read first, and the group is read at the hash of that block, so the fee and the reads are of one block whatever happens to the chain in between.

Everywhere else it is read inside the call:

  • A call that offers no fee is run with a base fee of zero by most clients: Geth, reth, Nethermind, Nitro and those built on them. So a group that reads the base fee offers one: maxFeePerGas of 2^64 - 1 wei, and no tip. The node then runs it with the base fee of the block.
  • A fee has to be paid from a balance. The same eth_call sets one for its sender, the zero address, with a state override. Nothing is spent: it is a call.
  • What the other reads of that group see changes in two places. tx.gasprice is the base fee, where it is zero in a call that offers nothing. And the ether of the zero address is the balance that was set: a group that reads Call.balance of the zero address beside Call.baseFee gets that balance.
  • Whether a node can be asked this way is asked once, with one small eth_call, before the first group that reads the base fee.

Call.View<bigint>

The gas limit of the block.

(account: Address.Address) => Call.View<bigint>

The ether account holds, in wei.

One account is not what it holds on the chain in one case: the zero address, in a group that also reads Call.baseFee. That group’s call is paid from a balance set at that address, and that balance is what it reads there.

(block: bigint) => Call.View<Hash.Hash>

The hash of the block of that number. For a block the node does not have, 32 zero bytes.

For a block the chain no longer holds, it is a second request, eth_getBlockByNumber, because no contract can say it. A block that old does not change.

What a chain holds, and so what is read inside the call:

Chain Blocks a contract can give the hash of
with the contract of EIP-2935: Ethereum since Prague, and most chains that follow it the last 8,191
without it the last 256, with blockhash
ArbOS the last 8,191, and the last 256 from ArbSys. blockhash knows none of its blocks

The block of the call itself has no hash yet inside the call: asked for, it is the node’s too.

  • Each is a view on a getter of Multicall3, at 0xcA11bde05977b3631167028862bE2a173976CA11. That is what Call.encode and Call.key say of it. The request says which state it reads, so a reader that sends it alone asks the node directly: no Multicall3 is needed to read one.
  • The same value alone and in a group. Alone, the node says it. In a group, a contract says it, asked in the way that makes it say what the node says: checked on Geth, reth, Nethermind, Arbitrum Nitro, the OP Stack, Polygon, Scroll, BSC, zkSync Era and Rootstock.
  • A group is one request. Its values are read where its other reads are, so nothing ties two requests together, and nothing can come between them.
  • They take the options of a read. With from, gas or an override, a read does not join a group. With an override it is asked of the getter, so that the override applies.

As any read. None declares an error of its own.

Error When
Revert.Unknown Call.baseFee on a chain that has no base fee
AbiError a read with an override, at a block where Multicall3 is not deployed: nothing came back
TransportError the node does not have the block the read is at: MalformedResponse, “The node has no block …”
RpcError, TransportError the node answered with an error, or did not answer

Alone, each is one request to the Transport, made by Call.direct:

  1. Call.blockNumbereth_blockNumbernothing at a block named by its number
  2. Call.timestampeth_getBlockByNumber(block, false)or eth_getBlockByHash
  3. Call.chainIdeth_chainIdasked once per transport
  4. Call.baseFeeeth_getBlockByNumber(block, false)or eth_getBlockByHash
  5. Call.gasLimiteth_getBlockByNumber(block, false)or eth_getBlockByHash
  6. Call.balance(a)eth_getBalance(a, block)
  7. Call.blockHash(n)eth_getBlockByNumber(n, false)

With a stateOverride or a blockOverride, each is asked of the contract a group asks, in requests of its own:

  1. Call.read(Call.balance(a), { stateOverride })

    1. your nodeeth_call({ to: Multicall3, data: getEthBalance(a) }, block, stateOverride)
  2. Call.read(Call.blockNumber, { stateOverride })

    1. your nodeeth_call({ to: Multicall3, data: getBlockNumber() }, block, stateOverride)
    2. on ArbOS

      1. your nodeeth_call({ to: ArbSys, data: arbBlockNumber() }, block, stateOverride)
  3. Call.read(Call.baseFee, { stateOverride })

    1. your nodeeth_call({ to: Multicall3, data: getBasefee(), maxFeePerGas: 2^64 - 1, maxPriorityFeePerGas: 0 }, block, { …stateOverride, [the sender]: { balance: 2^200 } })
  4. Call.read(Call.blockHash(n), { stateOverride })

    1. your nodeeth_call({ to: 0x0000F908…2935, data: n }, block, stateOverride)
    2. your nodeeth_call({ to: Multicall3, data: getBlockHash(n) }, block, stateOverride)
    3. neither holds it

      1. your nodeeth_getBlockByNumber(n, false)

In a group, each is one more call of the aggregate3 that carries the reads:

  1. Call.all([Call.blockNumber, Call.timestamp, Call.balance(a), token.balanceOf(a)])

    1. your nodeeth_call({ to: Multicall3, data: aggregate3([ getBlockNumber(), getCurrentBlockTimestamp(), getEthBalance(a), balanceOf(a) ]) }, "latest")
    2. on ArbOS: the first call is { target: ArbSys, callData: arbBlockNumber() }

  2. Call.all([Call.baseFee, token.balanceOf(a)])

    1. your nodeeth_call({ to: Multicall3, data: aggregate3([ getBasefee(), balanceOf(a) ]), maxFeePerGas: 2^64 - 1, maxPriorityFeePerGas: 0 }, "latest", { [0x0000…0000]: { balance: 2^200 } })
  3. Call.all([Call.blockHash(n), token.balanceOf(a)])

    1. your nodeeth_call({ to: Multicall3, data: aggregate3([ { target: 0x0000F908…2935, callData: n }, getBlockHash(n), balanceOf(a) ]) }, "latest")the first call is to the contract of EIP-2935. On ArbOS the second is ArbSys.arbBlockHash(n)
    2. neither holds it

      1. your nodeeth_getBlockByNumber(n, false)

Where the base fee is the node’s:

  1. Call.all([Call.baseFee, token.balanceOf(a)])

    1. your nodeeth_getBlockByNumber("latest", false)its base fee, and its hash H
    2. your nodeeth_call({ to: token, data: balanceOf(a) }, { blockHash: H })

What a group has to know of its node is asked once, and kept with the transport:

  1. is the chain ArbOS? Asked beside the first group that reads a block number or a hash

    1. your nodeeth_getCode(ArbSys, "latest")
    2. no code: no

    3. code

      1. your nodeeth_call({ to: ArbSys, data: arbChainID(), gas: 100000 }, "latest")
      2. the chain id: yes

      3. anything else, or a revert: no

  2. does a fee make the base fee true? Asked before the first group that reads the base fee

    1. your nodeeth_call({ to: Multicall3, data: aggregate3([ getBasefee() ]), maxFeePerGas, … }, block, { [Multicall3]: { code }, [0x0000…0000]: { balance } })
    2. the fee it offered, or an error: no

    3. anything else: yes