eth_blockNumber - Optimism
Example code for the eth_blockNumber json-rpc method. Сomplete guide on how to use eth_blockNumber json-rpc in GetBlock.io Web3 documentation.
The eth_blockNumber method retrieves the current block number. This method is particularly useful for monitoring transaction confirmations, tracking block production, and ensuring applications stay up-to-date with the current chain height.
Parameters
None
Request Sample
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_blockNumber",
"params": [],
"id": "getblock.io"
}'import axios from 'axios';
const url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/";
const headers = { "Content-Type": "application/json" };
const payload = {
jsonrpc: "2.0",
method: "eth_blockNumber",
params: [],
id: "getblock.io"
};
axios.post(url, payload, { headers })
.then(response => {
if (response.status === 200) {
console.log("eth_blockNumber result:", response.data.result);
} else {
console.error("Error:", response.status, response.statusText);
}
})
.catch(error => {
console.error("Error:", error.response ? error.response.data : error.message);
});Response
A successful response returns the following:
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x7A69B2C"
}Response Parameters
id: A unique request identifier, matching theidsent in the request body.jsonrpc: Specifies the use of JSON-RPC version 2.0.result: The current block number as a hexadecimal string.0x7A69B2Cin decimal equals 128,449,324.
Use Case
The eth_blockNumber method is commonly used for:
Transaction monitoring
Synchronization checks
Block-based triggers
Confirmation counting
Error handling
404
Not found
Missing or invalid ACCESS_TOKEN.
Integration with Web3
The eth_blockNumber can help developers to:
Polling the chain every few seconds
Syncing contract state
Updating dashboards (TVL, gas metrics, transactions)
Last updated
Was this helpful?