Skip to content

Commit 7e41737

Browse files
authored
Add docs for polling block handlers (#485)
* Add docs for polling block handlers * Add spec version requirement for block handler filters
1 parent 6250440 commit 7e41737

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

website/pages/en/developing/creating-a-subgraph.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,8 @@ In addition to subscribing to contract events or function calls, a subgraph may
770770

771771
### Supported Filters
772772

773+
#### Call Filter
774+
773775
```yaml
774776
filter:
775777
kind: call
@@ -806,6 +808,45 @@ dataSources:
806808
kind: call
807809
```
808810

811+
#### Polling Filter
812+
813+
> **Requires `specVersion` >= 0.8.0**
814+
815+
> **Note:** Polling filters are only available on dataSources of `kind: ethereum`.
816+
817+
```yaml
818+
blockHandlers:
819+
- handler: handleBlock
820+
filter:
821+
kind: polling
822+
every: 10
823+
```
824+
825+
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.
826+
827+
#### Once Filter
828+
829+
> **Requires `specVersion` >= 0.8.0**
830+
831+
> **Note:** Once filters are only available on dataSources of `kind: ethereum`.
832+
833+
```yaml
834+
blockHandlers:
835+
- handler: handleOnce
836+
filter:
837+
kind: once
838+
```
839+
840+
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.
841+
842+
```ts
843+
export function handleOnce(block: ethereum.Block): void {
844+
let data = new InitialData(Bytes.fromUTF8('initial'))
845+
data.data = 'Setup data here'
846+
data.save()
847+
}
848+
```
849+
809850
### Mapping Function
810851

811852
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.

0 commit comments

Comments
 (0)