eth_blockNumber - HyperEVM
Example code for the eth_blockNumber JSON RPC method. Сomplete guide on how to use eth_blockNumber JSON RPC in GetBlock Web3 documentation.
This methods get the number of the most recent block.
Paramaters
None
Request
curl --location --request POST 'https://go.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 data = JSON.stringify({
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": "getblock.io"
});
const config = {
method: 'post',
url: 'https://go.getblock.io/<ACCESS-TOKEN>/',
headers: {
'Content-Type': 'application/json'
},
data: data
};
axios(config)
.then(response => console.log(JSON.stringify(response.data)))
.catch(error => console.log(error));Response
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x1a2b3c"
}Response Parameters
Field
Type
Description
result
string
Hexadecimal block number of the most recent block.
Use Case
The eth_blockNumber method is essential for:
Monitoring chain progress and health
Synchronization tracking
Block confirmation calculations
Event indexing starting points
Health checks and monitoring dashboards
Error Handling
Error Code
Message
Cause
-32603
Internal error
Node synchronization issue.
Web3 Integration
import ethers from 'ethers';
const provider = new ethers.JsonRpcProvider('https://go.getblock.io//');
async function getCode() {
const code = await provider.getCode('0xContractAddress');
console.log('Contract Code Length:', code.length);
console.log('Is Contract:', code !== '0x');
}
getCode();
import { createPublicClient, http } from "viem";
import { hyperEvm } from "viem/chains";
// Create Viem client with GetBlock
const client = createPublicClient({
chain: hyperEvm,
transport: http(import.meta.env.HYPER_ACCESS_TOKEN),
});
// Using the method through Viem
async function Call() {
try {
// Method-specific Viem implementation
const result = await client.request({
"method": "eth_getBlockByNumber",
"params": ["latest", true],
};
return result;
} catch (error) {
console.error("Viem Error:", error);
throw error;
}
}Last updated
Was this helpful?