Skip to main content

hl_getLatestBlockNumber

Return the highest block number currently available for a given stream.

When to Use This Method#

hl_getLatestBlockNumber is essential for:

  • Synchronization — Determine the current head before fetching batch blocks
  • Polling — Check for new blocks at regular intervals
  • Catch-up Logic — Calculate how far behind your consumer is
  • Health Monitoring — Verify the data pipeline is advancing

Request#

Endpoint#

POST https://api-hyperliquid-mainnet-jsonrpc.n.dwellir.com/<API-KEY>/hypercore

Headers#

HeaderValueRequired
Content-Typeapplication/jsonYes

Parameters#

This method accepts both positional and named parameters.

Positional params:

PositionTypeRequiredDescription
[0]stringYesData stream. Must be "trades"

Named params:

FieldTypeRequiredDescription
streamstringYesData stream. Must be "trades"

Example Request (positional params)#

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

Example Request (named params)#

{
"jsonrpc": "2.0",
"method": "hl_getLatestBlockNumber",
"params": { "stream": "trades" },
"id": 1
}

Response#

Success Response#

{
"jsonrpc": "2.0",
"result": 907628737,
"id": 1
}

The result is a bare integer representing the highest block number across all fill files.

Response Fields#

FieldTypeDescription
resultintegerThe highest block number available for the stream

Error Response#

{
"jsonrpc": "2.0",
"error": { "code": -32602, "message": "unsupported stream" },
"id": 1
}

Code Examples#

curl -s https://api-hyperliquid-mainnet-jsonrpc.n.dwellir.com/<API-KEY>/hypercore \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"method": "hl_getLatestBlockNumber",
"params": ["trades"],
"id": 1
}' | jq .

Common Use Cases#

1. Poll for New Blocks#

Check for new data at regular intervals:

async function pollForNewBlocks(callback, intervalMs = 5000) {
let lastSeen = await getLatestBlockNumber();
console.log(`Starting poll from block ${lastSeen}`);

setInterval(async () => {
const latest = await getLatestBlockNumber();

if (latest > lastSeen) {
console.log(`New blocks: ${lastSeen + 1} to ${latest}`);
callback(lastSeen + 1, latest);
lastSeen = latest;
}
}, intervalMs);
}

// Usage
pollForNewBlocks((from, to) => {
console.log(`Processing blocks ${from}${to}`);
});

2. Calculate Consumer Lag#

Monitor how far behind a consumer is:

def check_lag(consumer_block: int) -> dict:
latest = get_latest_block_number()
lag = latest - consumer_block

return {
'consumer_block': consumer_block,
'latest_block': latest,
'lag_blocks': lag,
'status': 'healthy' if lag < 100 else 'behind'
}

Error Handling#

Error CodeCauseSolution
-32602Unsupported streamUse "trades" as the stream value
-32600Array-wrapped requestSend a single JSON-RPC object, not an array
-32700Malformed JSONValidate your request JSON

Best Practices#

  1. Poll responsibly — Don't poll more frequently than every few seconds
  2. Use as a cursor — Combine with hl_getBatchBlocks for sequential data retrieval
  3. Monitor lag — Track the difference between your consumer position and the latest block
  4. Handle stale data — If the latest block number hasn't advanced, the upstream may be paused

Query HyperCore fill data with Dwellir's JSON-RPC API. Get your API key →