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

eth_getBlockByNumber

Returns information about a block by block number.

When to Use This Method

Use eth_getBlockByNumber to:

  • Query Block Details - Get complete block information
  • Monitor Chain Progress - Track new blocks and transactions
  • Analyze Cross-Chain Activity - Review omnichain transactions
  • Historical Analysis - Study past network activity
  • Transaction Verification - Confirm transaction inclusion

Parameters

  1. Block Parameter (required):

    • latest - Most recent block
    • earliest - Genesis block
    • pending - Pending state
    • safe - Latest safe block
    • finalized - Latest finalized block
    • Block number as hexadecimal
  2. Transaction Details (required):

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

Returns

Block object with:

  • number: Block number
  • hash: Block hash
  • parentHash: Parent block hash
  • timestamp: Unix timestamp
  • transactions: Array of transactions
  • gasLimit: Block gas limit
  • gasUsed: Total gas used
  • And more fields...

Implementation Examples

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

# Get specific block with only transaction hashes
curl -X POST https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getBlockByNumber",
"params": [
"0x5BAD55",
false
],
"id": 1
}'

Example Response

{
"jsonrpc": "2.0",
"id": 1,
"result": {
"difficulty": "0x0",
"extraData": "0x",
"gasLimit": "0x1c9c380",
"gasUsed": "0x5208",
"hash": "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"miner": "0x0000000000000000000000000000000000000000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000000",
"number": "0x5bad55",
"parentHash": "0x9b3e4f7a65f3c2c1e8c7a8a0d5f6e4c3b2a1f0e9d8c7b6a5f4e3d2c1b0a9f8e7",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": "0x220",
"stateRoot": "0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff",
"timestamp": "0x65a7b4d2",
"totalDifficulty": "0x0",
"transactions": [
"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"
],
"transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"uncles": []
}
}

Omnichain Block Analysis

ZetaChain blocks contain cross-chain transaction information:

class OmnichainBlockAnalyzer {
constructor(provider) {
this.provider = provider;
}

async analyzeCrossChainActivity(blockNumber) {
const block = await this.provider.getBlock(blockNumber, true);

const crossChainTxs = [];
const regularTxs = [];

for (const tx of block.transactions) {
if (this.isCrossChainTx(tx)) {
const decoded = await this.decodeCrossChainTx(tx);
crossChainTxs.push({
hash: tx.hash,
from: tx.from,
sourceChain: 7000,
destChain: decoded.destChainId,
amount: ethers.formatEther(tx.value),
message: decoded.message
});
} else {
regularTxs.push(tx);
}
}

return {
blockNumber: block.number,
timestamp: block.timestamp,
totalTransactions: block.transactions.length,
crossChainTransactions: crossChainTxs.length,
regularTransactions: regularTxs.length,
crossChainDetails: crossChainTxs,
gasUsed: block.gasUsed,
baseFeePerGas: block.baseFeePerGas
};
}

isCrossChainTx(tx) {
// Check if transaction is to connector contract
const connectorAddress = '0x239e96c8f17C85c30100AC26F635Ea15f23E9c67';
return tx.to?.toLowerCase() === connectorAddress.toLowerCase();
}
}

Common Use Cases

1. Block Explorer Implementation

class BlockExplorer {
async getBlockDetails(blockId) {
const block = await provider.getBlock(blockId, true);

return {
overview: {
height: block.number,
hash: block.hash,
timestamp: new Date(block.timestamp * 1000),
transactionCount: block.transactions.length,
gasUsed: block.gasUsed,
gasLimit: block.gasLimit,
baseFeePerGas: block.baseFeePerGas
},
transactions: await this.processTransactions(block.transactions),
metrics: {
utilizationRate: (Number(block.gasUsed) / Number(block.gasLimit) * 100).toFixed(2) + '%',
avgGasPrice: this.calculateAvgGasPrice(block.transactions)
}
};
}
}

2. Chain Activity Monitor

async function monitorChainActivity(duration = 60000) {
const startBlock = await provider.getBlockNumber();
const stats = {
blocks: [],
totalTransactions: 0,
totalGasUsed: 0n,
crossChainTxCount: 0
};

const interval = setInterval(async () => {
const currentBlock = await provider.getBlockNumber();

for (let i = startBlock + 1; i <= currentBlock; i++) {
const block = await provider.getBlock(i, true);
stats.blocks.push(block);
stats.totalTransactions += block.transactions.length;
stats.totalGasUsed += block.gasUsed;

// Count cross-chain transactions
for (const tx of block.transactions) {
if (tx.to === '0x239e96c8f17C85c30100AC26F635Ea15f23E9c67') {
stats.crossChainTxCount++;
}
}
}
}, 6000); // Check every block (6 seconds)

setTimeout(() => {
clearInterval(interval);
console.log('Chain Activity Summary:', stats);
}, duration);
}

3. Transaction Finality Checker

async function checkTransactionFinality(txHash, confirmations = 12) {
const receipt = await provider.getTransactionReceipt(txHash);
if (!receipt) throw new Error('Transaction not found');

const txBlock = await provider.getBlock(receipt.blockNumber, false);
const currentBlock = await provider.getBlockNumber();
const currentConfirmations = currentBlock - receipt.blockNumber;

return {
transactionHash: txHash,
blockNumber: receipt.blockNumber,
blockHash: txBlock.hash,
timestamp: new Date(txBlock.timestamp * 1000),
confirmations: currentConfirmations,
finalized: currentConfirmations >= confirmations,
requiredConfirmations: confirmations
};
}

Block Fields Reference

FieldTypeDescription
numberQuantityBlock number
hashData, 32 bytesBlock hash
parentHashData, 32 bytesParent block hash
nonceData, 8 bytesProof of work nonce
sha3UnclesData, 32 bytesSHA3 of uncles data
logsBloomData, 256 bytesBloom filter for logs
transactionsRootData, 32 bytesRoot of transaction trie
stateRootData, 32 bytesRoot of state trie
receiptsRootData, 32 bytesRoot of receipts trie
minerData, 20 bytesAddress of miner
difficultyQuantityBlock difficulty
totalDifficultyQuantityTotal chain difficulty
extraDataDataExtra data field
sizeQuantityBlock size in bytes
gasLimitQuantityMaximum gas allowed
gasUsedQuantityTotal gas used
timestampQuantityUnix timestamp
transactionsArrayTransaction objects or hashes
unclesArrayUncle block hashes

Best Practices

  1. Use false for transaction details when only block info is needed
  2. Cache frequently accessed blocks
  3. Batch multiple block requests when analyzing ranges
  4. Monitor reorgs in recent blocks
  5. Handle null responses for pending blocks

Error Codes

CodeMessageDescription
-32600Invalid RequestInvalid JSON
-32602Invalid paramsInvalid method parameters
-32603Internal errorInternal JSON-RPC error
-32000Block not foundSpecified block doesn't exist