Overview
Triggers allow you to run read-only smart contract functions as part of Streams processing and include the results directly in your webhook payloads. This enables powerful real-time enrichment, such as:- Fetching token balances during transfers
- Reading contract state when an event fires
- Attaching computed on-chain data to each streamed event
How Triggers Work
A trigger defines:- When it should run (which event type)
- Which contract function to call
- What inputs to pass (static values or dynamic selectors)
- Moralis executes the read-only contract call
- The result is attached to the corresponding event object
- The enriched event is delivered in the webhook
Supported Trigger Types
Triggers can run against different parts of a webhook payload.| Type | Description |
|---|---|
tx | Run once per transaction |
log | Run per decoded contract event |
erc20transfer | Run per ERC-20 transfer |
erc20approval | Run per ERC-20 approval |
nfttransfer | Run per NFT transfer |
Trigger Definition
A trigger is defined using the following structure:Trigger Fields Explained
type
Specifies which event type the trigger runs against.
Example:
contractAddress
The address of the contract containing the function to call.
- Must be a valid address or a selector
- Selectors allow dynamic resolution per event
functionAbi
The ABI of a single read-only function.
Requirements:
- Must be a
vieworpurefunction - Arrays of ABI items are not supported
- Selectors are not supported inside ABI definitions
inputs (optional)
Inputs passed to the function call.
- Order must match the function ABI
- Values can be static or selectors
- Structs are supported using arrays
topic0 (optional)
Restricts execution to a specific event signature.
- Only valid when
typeislog - Requires the event ABI to be present in the stream
- Selectors are not allowed
callFrom (optional)
Overrides msg.sender for the contract call.
- Must be a valid address or selector
- Useful for contracts with access-controlled view functions
Selectors
Selectors dynamically reference values from the current webhook event.- Begin with
$ - Must be valid for the trigger type
- Validation ensures address selectors resolve to valid addresses
Common selectors
| Selector | Description |
|---|---|
$contract | Contract address for the current event |
$from | Sender address |
$to | Recipient address |
$value | Transfer amount |
Example: Fetch ERC-20 Balances During Transfers
This example enriches every ERC-20 transfer with the sender’s and receiver’s balances at the time of the transfer.Step 1: Define the ABI
Step 2: Create Triggers
Step 3: Resulting Webhook Enrichment
Each ERC-20 transfer will include trigger results:Error Handling
- Invalid triggers are rejected when creating or updating a stream
- Contract existence is not validated ahead of time
- If a contract call fails:
- The webhook is still delivered
- The trigger result includes an error message
Notes on Read-Only Functions
Triggers only support read-only contract calls:stateMutability: viewstateMutability: pure
When to Use Triggers
Triggers are ideal when you want to:- Enrich events with on-chain state
- Reduce API calls from your backend
- Attach contextual data at event time
- Keep webhook payloads self-contained

