eth_getBlockByNumber - zkSync
Example code for the eth_getBlockByNumber JSON-RPC method. Сomplete guide on how to use eth_getBlockByNumber JSON-RPC in GetBlock.io Web3 documentation.
Returns information about an L2 block by block number. Pass "latest", "earliest", "pending", "safe", or "finalized" as a block tag, or a hex-encoded block number. "finalized" reflects the latest block whose L1 batch has been executed on the Ethereum mainnet.
Parameters
blockParameter
string
Yes
Block number in hex, or "latest", "earliest", "pending", "safe", "finalized"
fullTransactions
boolean
Yes
If true, returns full transaction objects; if false, only hashes
Request Example
curl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_getBlockByNumber",
"params": [
"latest",
false
],
"id": "getblock.io"
}'import axios from 'axios';
const data = JSON.stringify({
"jsonrpc": "2.0",
"method": "eth_getBlockByNumber",
"params": [
"latest",
false
],
"id": "getblock.io"
});
const config = {
method: 'post',
url: 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
headers: {
'Content-Type': 'application/json'
},
data: data
};
axios(config)
.then(response => console.log(JSON.stringify(response.data, null, 2)))
.catch(error => console.log(error));Response Example
Response Parameters
result.number
string
L2 block number (hex)
result.hash
string
L2 block hash (32 bytes hex)
result.parentHash
string
Hash of the parent L2 block
result.timestamp
string
Unix timestamp of the block (hex)
result.gasUsed
string
Total gas used by transactions in this block (hex)
result.transactions
array
Array of transaction hashes, or full transaction objects if fullTransactions=true
result.l1BatchNumber
string
L1 batch number containing this L2 block (zkSync extension)
result.l1BatchTimestamp
string
Unix timestamp of the L1 batch (zkSync extension)
Use Cases
Block-by-block indexing of zkSync Era transactions
Building explorers showing L1 batch grouping
Computing per-block statistics on L2
Error Handling
403
Forbidden
Missing or invalid <ACCESS-TOKEN>
-32602
Invalid params
Request parameters are missing or malformed
429
Too Many Requests
Rate limit exceeded for your plan
SDK Integration
Last updated
Was this helpful?