eth_blockNumber
Returns the number of the most recent block on Optimism Layer 2.
When to Use This Method
eth_blockNumber
is essential for:
- Synchronization Monitoring - Track if your node is synced
- Block-based Operations - Get reference point for other RPC calls
- State Tracking - Monitor blockchain progression
- Application Polling - Check for new blocks periodically
Parameters
None. This method takes no parameters.
{
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 1
}
Returns
QUANTITY
- Integer of the current block number.
- Type: Hexadecimal string
- Format:
0x
prefixed - Example:
0x1b4
(436 in decimal)
Implementation Examples
- cURL
- JavaScript
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_blockNumber",
"params": [],
"id": 1
}'
// Using ethers.js
import { JsonRpcProvider } from 'ethers';
const provider = new JsonRpcProvider('https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY');
async function getCurrentBlockNumber() {
const blockNumber = await provider.getBlockNumber();
console.log('Current block number:', blockNumber);
return blockNumber;
}
// Using raw JSON-RPC
async function getBlockNumberRaw() {
const response = await fetch('https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_blockNumber',
params: [],
id: 1
})
});
const data = await response.json();
const blockNumber = parseInt(data.result, 16);
console.log('Current block number:', blockNumber);
return blockNumber;
}
Response Example
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x75bcd15"
}
This represents block number 123,456,789
in decimal.
Need help? Contact our support team or check the Optimism documentation.