Block-level context — information about the block being executed, exposed to the EVM via environment opcodes.
Fields
| Field | Opcode | Description |
|---|---|---|
number | NUMBER (0x43) | Current block number |
timestamp | TIMESTAMP (0x42) | Block timestamp (seconds since epoch) |
coinbase | COINBASE (0x41) | Address of the block producer |
gaslimit | GASLIMIT (0x45) | Block gas limit |
prevrandao | PREVRANDAO (0x44) | Previous block's RANDAO mix (post-Merge) |
basefee | BASEFEE (0x48) | Block base fee from EIP-1559 |
blob_base_fee | BLOBBASEFEE (0x4A) | Block blob base fee from EIP-7516 |
chain_id | CHAINID (0x46) | Network ID (1=mainnet, 137=Polygon, etc.) |
hashes | BLOCKHASH (0x40) | Map of recent block numbers to their hashes |
parent_beacon_block_root | (no opcode) | Parent beacon block root (EIP-4788) |
parent_beacon_block_root
Added in Cancun (EIP-4788). Not exposed through an opcode — instead, the EL
client performs a system call into the beacon-roots contract at block start
to record this value keyed by the parent block's timestamp. User contracts
then CALL that contract to read historical beacon roots.
PREVRANDAO
Before The Merge, opcode 0x44 was DIFFICULTY. Post-Merge, the same opcode returns the RANDAO mix from the Beacon Chain — a source of on-chain randomness.
Summary
Functions
Returns the block hash for a given block number.
Creates a new block context with default values.
Creates a new block context with the given overrides.
Types
@type t() :: %EEVM.Context.Block{ basefee: non_neg_integer(), blob_base_fee: non_neg_integer(), chain_id: non_neg_integer(), coinbase: non_neg_integer(), gaslimit: non_neg_integer(), hashes: %{required(non_neg_integer()) => non_neg_integer()}, number: non_neg_integer(), parent_beacon_block_root: non_neg_integer(), prevrandao: non_neg_integer(), timestamp: non_neg_integer() }
Functions
@spec hash(t(), non_neg_integer()) :: non_neg_integer()
Returns the block hash for a given block number.
Returns 0 if the block number is not in the last 256 blocks or is the current/future block. This matches the EVM spec — BLOCKHASH can only access the most recent 256 ancestors.
@spec new() :: t()
Creates a new block context with default values.
Creates a new block context with the given overrides.
Example
iex> block = EEVM.Context.Block.new(number: 18_000_000, chain_id: 1)
iex> block.number
18000000