⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip the expensive compute units.
Switch Today →
Skip to main content

eth_getBlockByNumber

Returns information about a block by block number on Optimism Layer 2.

When to Use This Method

eth_getBlockByNumber is essential for:

  • Block Analysis - Examine specific blocks on Optimism L2
  • Transaction Tracking - Get all transactions in a block
  • Historical Data - Access past block information
  • Chain Monitoring - Monitor block production and health

Parameters

  1. Block Number - QUANTITY|TAG

    • Block number in hex format (e.g., 0x1b4)
    • "latest" - Most recent block
    • "earliest" - Genesis block
    • "pending" - Pending block
    • "safe" - Latest safe block
    • "finalized" - Latest finalized block
  2. Full Transactions - BOOLEAN

    • true - Return full transaction objects
    • false - Return only transaction hashes
{
"jsonrpc": "2.0",
"method": "eth_getBlockByNumber",
"params": ["latest", true],
"id": 1
}

Returns

Block object with the following fields:

  • number - Block number
  • hash - Block hash
  • parentHash - Hash of parent block
  • timestamp - Unix timestamp
  • transactions - Array of transactions or hashes
  • gasUsed - Total gas used in block
  • gasLimit - Gas limit for block

Implementation Examples

curl -X POST https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getBlockByNumber",
"params": ["latest", true],
"id": 1
}'

Response Example

{
"jsonrpc": "2.0",
"id": 1,
"result": {
"number": "0x75bcd15",
"hash": "0x1d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df2",
"parentHash": "0x2d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df1",
"timestamp": "0x55ba467c",
"transactions": [...],
"gasUsed": "0x47e7c4",
"gasLimit": "0x1c9c380"
}
}

Need help? Contact our support team or check the Optimism documentation.