> For the complete documentation index, see [llms.txt](https://docs-unified.crypto-chief.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-unified.crypto-chief.com/guides/events-backfill.md). Agents can also search and read this documentation through its [MCP server](https://docs-unified.crypto-chief.com/~gitbook/mcp).

# Event Backfill with an EventStream Selection

## Event Backfill with an EventStream Selection

[`POST /v1/events/search`](https://docs-unified.crypto-chief.com/api-reference/events.md) runs an EventStream `selection` over history. The same object that defines a subscription returns the events it would have delivered in a past block or time range — same types, same payloads, same ids.

Use it to:

* load the history a new subscription does not cover, before its first block;
* try a selection on real data before you subscribe and pay for deliveries;
* investigate a contract or an address over a period.

### 1. Take the selection

Use the `selection` of an existing subscription (`subscriptions/get` returns it in `config.selection`), or write one. A contract event on Ethereum:

```json
{
  "networks": ["ETH_MAINNET"],
  "types": ["contract.event"],
  "contracts": [{ "network": "ETH_MAINNET", "address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" }],
  "events": [{ "signature": "Approval(address,address,uint256)" }]
}
```

### 2. Check the networks

`GET /v1/networks/{network}` → `capabilities.events_search`:

* `types` — the event types the network can search;
* `max_block_range` — the longest block range per call, `null` for no limit;
* `capabilities.transfers.history_from` — where its history starts.

A selection field a network does not support is `422 UNSUPPORTED_CAPABILITY` with the field named. It is never dropped silently, so a search answers exactly the question the selection asks.

### 3. Walk the range

A block range is for one network. Split a long range into windows of `max_block_range` blocks and page through each window:

{% tabs %}
{% tab title="JavaScript" %}

```javascript
async function* search(selection, fromBlock, toBlock, maxRange) {
  for (let start = BigInt(fromBlock); start < BigInt(toBlock); start += BigInt(maxRange)) {
    const end = start + BigInt(maxRange) < BigInt(toBlock) ? start + BigInt(maxRange) : BigInt(toBlock);
    let cursor = null;
    do {
      const { http, data } = await api("POST", "/events/search", {}, {
        selection,
        range: { from_block: String(start), to_block: String(end) },
        min_stage: "final",
        order: "asc",
        limit: 1000,
        cursor,
      });
      if (http !== 200) throw new Error(`${http} ${data.error}: ${data.message}`);
      yield* data.items;
      cursor = data.next_cursor;
    } while (cursor);
  }
}

for await (const e of search(selection, "23900000", "23950000", 10000)) {
  console.log(e.block.height, e.id, e.payload);
}
```

{% endtab %}

{% tab title="Python" %}

```python
def search(selection, from_block, to_block, max_range):
    start, to_block = int(from_block), int(to_block)
    while start < to_block:
        end = min(start + max_range, to_block)
        cursor = None
        while True:
            status, data, _ = api("POST", "/events/search", body={
                "selection": selection,
                "range": {"from_block": str(start), "to_block": str(end)},
                "min_stage": "final",
                "order": "asc",
                "limit": 1000,
                "cursor": cursor,
            })
            if status != 200:
                raise RuntimeError(f"{status} {data.get('error')}: {data.get('message')}")
            yield from data["items"]
            cursor = data["next_cursor"]
            if not cursor:
                break
        start = end

for e in search(selection, "23900000", "23950000", 10000):
    print(e["block"]["height"], e["id"], e["payload"])
```

{% endtab %}
{% endtabs %}

Where `max_block_range` is `null`, one window covers the whole range. Each page is charged once for each network of the selection, so a long walk over a busy contract costs its page count times its networks: narrow the selection before widening the range.

For several networks at once, use a time range — `{"from": "2026-11-01T00:00:00Z", "to": "2026-11-29T00:00:00Z"}` — and the events of all networks come in one ordered list: by block time, then network.

### 4. Hand over to the stream

Search up to a little past the subscription's first block, and merge history and deliveries on `(network, id)` = `(network, occurrence_id)`. The full procedure is [Deposit Reconciliation with EventStream](https://docs-unified.crypto-chief.com/guides/deposit-reconciliation.md).

### What a search is not

* Not EventStream's event log: `events/list` returns what your subscriptions captured in the last 30 days; a search reads the networks for any covered range, subscription or not.
* Not a delivery: there is no `event_id`, `sequence` or `relation`. Each result is the current state of one occurrence.
* Not a scripted filter: ESJS scripts of a subscription are not run; only `selection` applies.
