evmEventDecoder() bundles an EVM log query with a decoding transform into a single reusable module. Pass the result as an output to evmPortalStream:
evmEventDecoder() can:
- Fetch from specific contracts: pass an array of addresses to
contracts. Omit it entirely to receive matching events from every contract onchain. - Filter by indexed parameters: instead of a bare event, supply
{ event, params }to select only logs where specific indexed arguments match. - Dynamically discover contracts via factories: pass a
contractFactory()tocontractsinstead of a static list. See the Factory guide. - Handle decode errors with a custom
onErrorcallback instead of letting them propagate.
Specifying events
Theevents parameter maps output field names to event specifications. There are three ways to obtain one: commonAbis covers standard tokens, defineAbi() is the standard route for everything else, and typegen generates ABI modules as files if you prefer that.
commonAbis
commonAbis is a built-in collection of ABI modules for common token standards. It currently contains one module, erc20:
commonAbis reference for the full list of available events and functions.
Raw JSON via defineAbi()
defineAbi() turns a JSON ABI into an ABI module at runtime. There is no code generation step: declare the ABI inline, or paste it from the block explorer, and use it directly. With an inline ABI, TypeScript infers the exact decoded types for scalar fields:
defineAbi() reads their abi field automatically:
any, since TypeScript cannot inspect the runtime JSON value at compile time. Inline as const ABIs and typegen modules do not have this limitation.
Typegen modules
If you prefer generated files, or want full static typing for an ABI that lives in a JSON file,@subsquid/evm-typegen generates TypeScript ABI modules from JSON ABIs. Each generated module exports typed events and functions objects, translating Solidity types to TypeScript, so event argument types are statically known at compile time.
Install the tool:
src/abi/your-contract.ts. The tool also accepts a contract address (requires specifying --chain-id) or an arbitrary URL.
Use events from a generated module exactly as with commonAbis: