Skip to content

Commit

Permalink
Add docs for polling block handlers (#485)
Browse files Browse the repository at this point in the history
* Add docs for polling block handlers

* Add spec version requirement for block handler filters
  • Loading branch information
incrypto32 authored Sep 8, 2023
1 parent 6250440 commit 7e41737
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions website/pages/en/developing/creating-a-subgraph.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ In addition to subscribing to contract events or function calls, a subgraph may

### Supported Filters

#### Call Filter

```yaml
filter:
kind: call
Expand Down Expand Up @@ -806,6 +808,45 @@ dataSources:
kind: call
```

#### Polling Filter

> **Requires `specVersion` >= 0.8.0**

> **Note:** Polling filters are only available on dataSources of `kind: ethereum`.

```yaml
blockHandlers:
- handler: handleBlock
filter:
kind: polling
every: 10
```

The defined handler will be called once for every `n` blocks, where `n` is the value provided in the `every` field. This configuration allows the subgraph to perform specific operations at regular block intervals.

#### Once Filter

> **Requires `specVersion` >= 0.8.0**

> **Note:** Once filters are only available on dataSources of `kind: ethereum`.

```yaml
blockHandlers:
- handler: handleOnce
filter:
kind: once
```

The defined handler with the once filter will be called only once before all other handlers run. This configuration allows the subgraph to use the handler as an initialization handler, performing specific tasks at the start of indexing.

```ts
export function handleOnce(block: ethereum.Block): void {
let data = new InitialData(Bytes.fromUTF8('initial'))
data.data = 'Setup data here'
data.save()
}
```

### Mapping Function

The mapping function will receive an `ethereum.Block` as its only argument. Like mapping functions for events, this function can access existing subgraph entities in the store, call smart contracts and create or update entities.
Expand Down

0 comments on commit 7e41737

Please sign in to comment.