eth_blockNumber - Bitlayer
This method returns the number of the most recent block, as a hex-encoded integer. It is the primary way to read the current chain tip on Bitlayer.
Parameters
This method does not require any parameters. Send the request with an empty params array.
Request
Use one of these request examples:
bashcurl --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"
}'example.js
javascriptconst axios = require('axios');
const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
jsonrpc: '2.0',
method: 'eth_blockNumber',
params: [],
id: 'getblock.io'
}, {
headers: { 'Content-Type': 'application/json' }
});
console.log(response.data.result);example.py
pythonimport requests
response = requests.post(
'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
headers={'Content-Type': 'application/json'},
json={
'jsonrpc': '2.0',
'method': 'eth_blockNumber',
'params': [],
'id': 'getblock.io'
}
)
print(response.json())example.rs
rustuse reqwest::Client;
use serde_json::{json, Value};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let response = client
.post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
.header("Content-Type", "application/json")
.json(&json!({
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": "getblock.io"
}))
.send()
.await?
.json::<Value>()
.await?;
println!("Result: {}", response["result"]);
Ok(())
}Response
A successful response is:
json{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0xb71b00"
}Response parameters
| Parameter | Type | Description |
|---|---|---|
| jsonrpc | string | JSON-RPC protocol version ("2.0") |
| id | string | Request identifier matching the request |
| result | string | Hex-encoded number of the latest block |
Use cases
- Chain tip polling: Track new blocks on a ~1 second cadence for indexers
- Confirmation counting: Compute confirmations as tip minus a transaction's block number
- Log range bounds: Set
toBlockfor aneth_getLogsquery to the current tip - Sync checks: Compare a local indexer height against the network tip
Error handling
| Error Code | Message | Description |
|---|---|---|
| -32603 | Internal error | The node failed to return the latest block number |
| -32601 | Method not found | The eth module is disabled on the client build |
Web3 integration
Use either library:
ethers-example.js
javascriptimport { ethers } from 'ethers';
const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');
const blockNumber = await provider.getBlockNumber();viem-example.js
javascriptimport { createPublicClient, http } from 'viem';
const client = createPublicClient({
transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});
const blockNumber = await client.getBlockNumber();