Docs

hl_getBatchBlocks - Get Batch Fill Blocks

Retrieve a batch of fill blocks for a given stream and block range via the HyperCore JSON-RPC API.

Return fill blocks in a [from, to] range for a given stream.

When to Use This Method

hl_getBatchBlocks is essential for:

  • Backfilling — Retrieve historical fill data in bulk
  • Batch Processing — Process trade events in ordered block ranges
  • Analytics Pipelines — Feed fill data into downstream systems
  • Reconciliation — Verify trade execution across block ranges

Common Use Cases

1. Sequential Backfill

Fetch all blocks from a known starting point to the latest:

JavaScript
async function backfill(startBlock) {
  const response = await fetch(ENDPOINT, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      jsonrpc: '2.0',
      method: 'hl_getLatestBlockNumber',
      params: { stream: 'trades' },
      id: 1
    })
  });
  const { result: latestBlock } = await response.json();

  let current = startBlock;
  while (current <= latestBlock) {
    const to = Math.min(current + 99, latestBlock);
    const blocks = await getBatchBlocks(current, to);
    console.log(`Fetched blocks ${current}–${to}: ${blocks.length} blocks`);

    for (const block of blocks) {
      // Process each block
    }

    current = to + 1;
  }
}

2. Event Counting

Count fill events across a block range:

Python
def count_events(from_block: int, to_block: int) -> dict:
    blocks = get_batch_blocks(from_block, to_block)

    total_events = 0
    for block in blocks:
        total_events += len(block['events'])

    return {
        'block_range': f"{from_block}–{to_block}",
        'blocks_returned': len(blocks),
        'total_events': total_events
    }

Best Practices

  1. Respect the batch limit — Keep ranges at or below 100 blocks per request
  2. Use sequential fetching — Combine with hl_getLatestBlockNumber to walk forward
  3. Handle sparse ranges — Some blocks in a range may have no events
  4. Implement retries — Use exponential backoff for transient errors

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