Back to Hub
CREATED BY CHAINLINK LABS

Event Reactor

Listen for on-chain events, fetch off-chain context, and respond on-chain using the event → read → decide → write pattern.

Get the template
cre init --template=event-reactor-ts
View on GitHub

What This Template Does

This template demonstrates the event → read → decide → write pattern using a LogTrigger for real-time on-chain reaction.

The workflow:

  1. LogTrigger fires when MonitoredToken emits a LargeTransfer event
  2. Decodes the event using typed bindings (from, to, amount, timestamp)
  3. Reads ReactorConsumer state to check if the sender is already flagged
  4. 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 MonitoredToken or point to a different contract
  • Change reaction logic — Update the onLargeTransfer workflow and _processReport in the contract
  • Add off-chain API calls — Use cre.capabilities.HTTPClient to fetch external data before deciding

For full details, see the TypeScript README on GitHub.

Get the latest Chainlink content straight to your inbox.