What This Template Does
This template demonstrates the event → read → decide → write pattern using a LogTrigger for real-time on-chain reaction.
The workflow:
- LogTrigger fires when
MonitoredTokenemits aLargeTransferevent - Decodes the event using typed bindings (from, to, amount, timestamp)
- Reads
ReactorConsumerstate to check if the sender is already flagged - Decides: If not flagged, sends a signed report to flag the address on-chain. If already flagged, logs and skips.
Key Technologies:
- CRE (Chainlink Runtime Environment) — Event-driven workflow orchestration with DON consensus
- LogTrigger — Real-time event reaction without cron delays
- State-aware decisions — Checks existing state before acting to avoid duplicates
How It Works
Getting Started
1 Install dependencies
cd my-workflow && bun install && cd .. && cd contracts && bun install && cd ..
2 Run tests
cd my-workflow && bun test
3 Simulate the workflow
Simulate with a pre-emitted event on Sepolia:
cre workflow simulate my-workflow --target staging-settings \
--non-interactive \
--trigger-index 0 \
--evm-tx-hash 0xe5ac97df3f93c5fdc89690a71d68a8e5ebd35ec8ba9c6cb5d1069f5818222553 \
--evm-event-index 0
Emit your own LargeTransfer event:
cast send 0x805A04e5C8b2dcb2B26C9e9C9aa12ce34374A35b \
"simulateLargeTransfer(address,uint256)" \
0x000000000000000000000000000000000000dEaD \
2000000000000000000000
4 Deploy your own contracts
Deploy MonitoredToken (no constructor args):
forge create src/MonitoredToken.sol:MonitoredToken \
--broadcast --private-key <KEY> --rpc-url <RPC>
Deploy ReactorConsumer with the forwarder address:
forge create src/ReactorConsumer.sol:ReactorConsumer \
--broadcast --private-key <KEY> --rpc-url <RPC> \
--constructor-args 0x15fc6ae953e024d975e77382eeec56a9101f9f88
Customization
- Change monitored event — Modify
MonitoredTokenor point to a different contract - Change reaction logic — Update the
onLargeTransferworkflow and_processReportin the contract - Add off-chain API calls — Use
cre.capabilities.HTTPClientto fetch external data before deciding
For full details, see the TypeScript README on GitHub.
CREATED BY CHAINLINK LABS