diff --git a/docs/HyperIndex/Advanced/effect-api.md b/docs/HyperIndex/Advanced/effect-api.md index 563e33ac..8f68a440 100644 --- a/docs/HyperIndex/Advanced/effect-api.md +++ b/docs/HyperIndex/Advanced/effect-api.md @@ -51,9 +51,10 @@ The first argument is an options object that describes the effect: - `name` (required) - the name of the effect used for debugging and logging - `input` (required) - the input type of the effect -- `output` (required) - the output type of the effect +- `output` (required) - the output type of the effect (not required for `unorderedAfterCommit` and `orderedAfterCommit` modes which return `void`) - `rateLimit` (required) - the maximum calls allowed per timeframe, or `false` to disable - `cache` (optional) - save effect results in the database to prevent duplicate calls (Starting from `envio@2.26.0`) +- `mode` (optional) - the execution intent of the effect. Defaults to `speculative`. See [Execution Modes](#execution-modes). The second argument is a function that will be called with the effect's input. @@ -64,10 +65,15 @@ After defining an effect, you can use `context.effect` to call it from your hand The `context.effect` function accepts an effect as the first argument and the effect's input as the second argument: ```typescript -ERC20.Transfer.handler(async ({ event, context }) => { - const metadata = await context.effect(getMetadata, event.params.from); - // Process the event with the metadata -}); +import { indexer } from "envio"; + +indexer.onEvent( + { contract: "ERC20", event: "Transfer" }, + async ({ event, context }) => { + const metadata = await context.effect(getMetadata, event.params.from); + // Process the event with the metadata + }, +); ``` ### Reading On-Chain State (eth_call) @@ -213,6 +219,68 @@ export const getBalance = createEffect( Watch the following video to learn more about createEffect and other updates introduced in [v2.32.0](https://github.com/enviodev/hyperindex/releases/tag/v2.32.0).