Overview
Block context instructions provide access to blockchain environment data within smart contract execution. These opcodes allow contracts to query information about the current block, historical blocks, and chain configuration. Opcode Range:0x40 - 0x4A (11 opcodes)
Instructions
Core Block Information
| Opcode | Name | Gas | Introduced | Description |
|---|---|---|---|---|
0x40 | BLOCKHASH | 20 | Frontier | Get hash of recent block |
0x41 | COINBASE | 2 | Frontier | Get block beneficiary address |
0x42 | TIMESTAMP | 2 | Frontier | Get block timestamp |
0x43 | NUMBER | 2 | Frontier | Get block number |
0x44 | DIFFICULTY | 2 | Frontier | Get block difficulty (PREVRANDAO post-Merge) |
0x45 | GASLIMIT | 2 | Frontier | Get block gas limit |
Chain and Account Context
| Opcode | Name | Gas | Introduced | Description |
|---|---|---|---|---|
0x46 | CHAINID | 2 | Istanbul | Get chain identifier |
0x47 | SELFBALANCE | 5 | Istanbul | Get balance of executing contract |
EIP-4844 Blob Context
| Opcode | Name | Gas | Introduced | Description |
|---|---|---|---|---|
0x49 | BLOBHASH | 3 | Cancun | Get versioned blob hash by index |
0x4A | BLOBBASEFEE | 2 | Cancun | Get current blob base fee |
Historical Evolution
Frontier (Genesis)
BLOCKHASH,COINBASE,TIMESTAMP,NUMBER,DIFFICULTY,GASLIMIT- Original block context operations for basic blockchain awareness
Istanbul (EIP-1344, EIP-1884)
CHAINID- Enable replay protection across different chainsSELFBALANCE- More efficient balance queries for current contract
Paris (The Merge)
DIFFICULTYrepurposed asPREVRANDAOfor post-merge randomness
Cancun (EIP-4844)
BLOBHASH,BLOBBASEFEE- Support for proto-danksharding blob transactions
Common Patterns
Timestamp-Based Logic
Block-Based Randomness (Legacy)
Chain-Specific Behavior
Historical Block Queries
Gas Costs Summary
| Category | Gas Cost | Opcodes |
|---|---|---|
| Fast | 3 | BLOBHASH |
| Quick | 2 | COINBASE, TIMESTAMP, NUMBER, DIFFICULTY, GASLIMIT, CHAINID, BLOBBASEFEE |
| Fast | 5 | SELFBALANCE |
| Ext | 20 | BLOCKHASH |
Security Considerations
Timestamp Manipulation
Block timestamps can be manipulated by miners within bounds (±15 seconds typically):Blockhash Limitations
BLOCKHASH only returns hashes for the most recent 256 blocks:
PREVRANDAO Considerations
Post-merge,DIFFICULTY returns PREVRANDAO - beacon chain randomness:
- More unpredictable than PoW difficulty
- Still not suitable for high-stakes randomness
- Use Chainlink VRF for critical applications
Chain ID Replay Protection
Always includeblock.chainid in transaction hashing for cross-chain protection:
Implementation Notes
TypeScript Usage
Related Instructions
- Context Instructions - Execution environment (origin, caller, callvalue)
- Storage Instructions - Persistent state access
- System Instructions - Contract creation and calls

