This method returns the number of the most recent block on the BNB Smart Chain. This is a fundamental method for tracking blockchain state and monitoring network progress. With BSC's ~3 second block times, this value updates frequently, making it essential for applications requiring real-time blockchain data.
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"
}'
javascriptconst axios = require('axios');
const url = 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/';
const payload = {
jsonrpc: '2.0',
method: 'eth_blockNumber',
params: [],
id: 'getblock.io'
};
axios.post(url, payload, {
headers: { 'Content-Type': 'application/json' }
})
.then(response => {
const blockNumber = parseInt(response.data.result, 16);
console.log('Current Block Number:', blockNumber);
})
.catch(error => console.error(error));
pythonimport requests
import json
url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"
payload = {
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": "getblock.io"
}
response = requests.post(url, headers={"Content-Type": "application/json"}, json=payload)
block_number = int(response.json()["result"], 16)
print(f"Current Block Number: {block_number}")
rustuse reqwest::Client;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let payload = json!({
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": "getblock.io"
});
let response = client
.post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
.header("Content-Type", "application/json")
.json(&payload)
.send()
.await?;
let result: serde_json::Value = response.json().await?;
println!("{:#?}", result);
Ok(())
}
javascriptconst { ethers } = require('ethers');
const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');
const blockNumber = await provider.getBlockNumber();
console.log('Current Block:', blockNumber);
javascriptimport { createPublicClient, http } from 'viem';
import { bsc } from 'viem/chains';
const client = createPublicClient({
chain: bsc,
transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});
const blockNumber = await client.getBlockNumber();
console.log('Current Block:', blockNumber);