⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

eth_blockNumber

Returns the number of the most recent block on TRON network.

When to Use This Method

eth_blockNumber is fundamental for:

  • Syncing Applications - Keep your dApp in sync with the latest blockchain state
  • Transaction Monitoring - Verify confirmations by comparing block numbers
  • Event Filtering - Set the correct block range for querying logs
  • Health Checks - Monitor node connectivity and sync status

Parameters

This method accepts no parameters.

{
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 1
}

Returns

QUANTITY - Integer of the current block number the node is synced to.

  • Type: Hexadecimal string
  • Format: 0x prefixed
  • Example: 0x37a6f80 (58290048 in decimal)

Implementation Examples

curl -X POST https://api-tron-jsonrpc.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 1
}'

Example Response

{
"jsonrpc": "2.0",
"id": 1,
"result": "0x37a6f80"
}

Common Use Cases

1. Block Confirmation Tracking

async function getConfirmations(txHash) {
const tx = await provider.getTransaction(txHash);
if (!tx || !tx.blockNumber) return 0;

const currentBlock = await provider.getBlockNumber();
return currentBlock - tx.blockNumber + 1;
}

// Wait for specific confirmations
async function waitForConfirmations(txHash, requiredConfirmations = 12) {
while (true) {
const confirmations = await getConfirmations(txHash);
if (confirmations >= requiredConfirmations) {
return confirmations;
}
await new Promise(resolve => setTimeout(resolve, 3000)); // 3 second blocks
}
}

2. Real-time Block Monitoring

let lastBlock = 0;

async function monitorBlocks() {
setInterval(async () => {
try {
const currentBlock = await provider.getBlockNumber();

if (currentBlock > lastBlock) {
console.log(`New block: ${currentBlock}`);
// Process new blocks
for (let i = lastBlock + 1; i <= currentBlock; i++) {
await processBlock(i);
}
lastBlock = currentBlock;
}
} catch (error) {
console.error('Block monitoring error:', error);
}
}, 3000); // Check every 3 seconds (TRON block time)
}

3. Event Filtering with Block Range

async function getRecentEvents(contractAddress, eventName, blockCount = 100) {
const currentBlock = await provider.getBlockNumber();
const fromBlock = currentBlock - blockCount;

const filter = {
address: contractAddress,
topics: [ethers.id(eventName)],
fromBlock: fromBlock,
toBlock: currentBlock
};

const logs = await provider.getLogs(filter);
return logs;
}

4. Node Sync Status Check

async function checkNodeSync() {
try {
const blockNumber = await provider.getBlockNumber();
const block = await provider.getBlock(blockNumber);

const currentTime = Date.now() / 1000;
const blockTime = block.timestamp;
const timeDiff = currentTime - blockTime;

if (timeDiff > 60) { // More than 60 seconds behind
console.warn(`Node is ${timeDiff} seconds behind`);
return false;
}

console.log(`Node is synced at block ${blockNumber}`);
return true;
} catch (error) {
console.error('Sync check failed:', error);
return false;
}
}

Best Practices

  1. Cache Block Numbers - Avoid excessive calls by caching recent block numbers
  2. Handle Hex Conversion - Always parse the hex result to decimal for calculations
  3. Monitor Block Production - TRON produces blocks every ~3 seconds
  4. Error Handling - Implement retry logic for network issues

Error Codes

CodeMessageDescription
-32600Invalid RequestThe JSON sent is not a valid Request object
-32601Method not foundThe method is not available
-32602Invalid paramsInvalid method parameters
-32603Internal errorInternal JSON-RPC error
-32000Node not syncedThe node is still syncing

Block Time Information

TRON network produces blocks approximately every 3 seconds, which is faster than Ethereum's ~12 seconds. This means:

  • 20 blocks per minute
  • 1,200 blocks per hour
  • 28,800 blocks per day