For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

The eth_blockNumber method returns the number of the most recent block on the Polygon blockchain. This method provides real-time insight into the blockchain's progress and is essential for applications that need to stay synchronized with the latest state of the network.

Parameters

  • None

Request

curl
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
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"}
axios.js
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

response.json
{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0x3A2B5C7"
}

Response Parameters

Field
Type
Description

jsonrpc

string

JSON-RPC version (2.0)

id

string

Request identifier

result

string

The latest block number in hexadecimal format. For example, "0x3A2B5C7" equals 61077959 in decimal

Use Case

The eth_blockNumber method is essential for:

  • Block synchronization: Verify if your application is synced with the network

  • Transaction confirmation: Monitor block progress while waiting for transaction confirmations

  • Time-based triggers: Execute actions when specific block heights are reached

  • Data indexing: Track the latest block for event scanning and data extraction

  • Health monitoring: Check if the node is producing new blocks

Example: Block Confirmation Monitor

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid ACCESS-TOKEN

-32600

Invalid Request

Malformed request body

-32603

Internal error

Node synchronization issues

Web3 Integration

Last updated

Was this helpful?