eth_blockNumber - Polygon
Example code for the eth_blockNumber json-rpc method. Сomplete guide on how to use eth_blockNumber json-rpc in GetBlock.io Web3 documentation.
Parameters
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"
}'wscat -c wss://go.getblock.io/<ACCESS-TOKEN>/
# wait for connection and send the request body
{"jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": "getblock.io"}import axios from 'axios';
const url = 'https://go.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));Response
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x3A2B5C7"
}Response Parameters
Field
Type
Description
Use Case
Example: Block Confirmation Monitor
Error Handling
Status Code
Error Message
Cause
Web3 Integration
Last updated
Was this helpful?