Docs

hl_getLatestBlockNumber - Get Latest Block Number

Get the highest block number currently available for a HyperCore data stream via the JSON-RPC API.

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

Endpoint

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

Use this JSON-RPC endpoint for trade-fill block cursors. It is not the HyperCore Info endpoint, which uses {"type": "..."} request bodies at https://api-hyperliquid-mainnet-info.n.dwellir.com/<API-KEY>/info.

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

Curl Example

Bash
curl -X POST 'https://api-hyperliquid-mainnet-jsonrpc.n.dwellir.com/YOUR_API_KEY/hypercore' \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "hl_getLatestBlockNumber",
    "params": { "stream": "trades" },
    "id": 1
  }'

If you receive {"code":-32601,"message":"method not found: hl_getBlockByNumber"}, the request body is using an unsupported method. Use hl_getLatestBlockNumber for the current cursor, or hl_getBatchBlocks for one or more fill blocks.

Common Use Cases

1. Poll for New Blocks

Check for new data at regular intervals:

JavaScript
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:

Python
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'
    }

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 →