On-chain IFTTT workflow orchestrator powered by Somnia Reactivity.
ReactiveFlow lets users create automated workflows that react to on-chain events — no bots, no keepers, no off-chain infrastructure. Define a trigger, set a condition, pick an action. The Somnia Reactivity precompile handles the rest.
WHEN a token transfer happens → ONLY IF amount >= 10,000 USDC → THEN emit an alert
┌──────────────┐ Somnia Validators ┌──────────────────┐
│ ERC-20 │──── detect Transfer ─────>│ ReactiveFlow │
│ Contract │ event on-chain │ ._onEvent() │
└──────────────┘ │ │
│ match trigger │
│ check condition │
│ execute action │
└──────────────────┘
ReactiveFlow leverages Somnia On-Chain Reactivity — a native protocol where validators automatically invoke smart contract callbacks when subscribed events fire. This eliminates the need for off-chain watchers entirely.
- User creates a Flow via the web UI (trigger + condition + action)
- Backend registers a Reactivity subscription through the precompile at
0x0100 - When the event fires, Somnia validators call
ReactiveFlow._onEvent() - The contract evaluates conditions and executes the action atomically in the same block
| Type | Description | Example |
|---|---|---|
| Token Transfer | ERC-20 Transfer events |
USDC whale movements |
| Price Threshold | DIA Oracle price updates | ETH/USD drops below $2,000 |
| DEX Swap | DEX swap events | Large swaps on any pair |
| Custom Event | Any contract event | Governance proposals, NFT mints |
>, <, >=, <=, ==, !=, or NONE (always execute)
Conditions evaluate either:
- PRICE — reads from DIA Oracle with 1-hour staleness check
- AMOUNT — extracts a uint256 from event data at a configurable byte offset
| Action | Description |
|---|---|
| Transfer Token | Send ERC-20 from user deposits to a recipient |
| Swap Tokens | Execute a DEX swap via any router contract |
| Contract Call | Call any function on any contract (up to 3M gas) |
| Emit Alert | Emit an on-chain alert event for monitoring |
reactiveflow/
├── packages/
│ ├── contracts/ # Solidity — ReactiveFlow.sol
│ │ ├── contracts/
│ │ ├── test/ # Hardhat + viem tests
│ │ └── scripts/ # Deploy, setup demos, create subscriptions
│ ├── frontend/ # React + Vite + TailwindCSS + shadcn/ui
│ │ └── src/
│ │ ├── pages/ # Landing, Dashboard, CreateFlow, FlowList, etc.
│ │ ├── components/ # Flow builder wizard, token selector, wallet
│ │ ├── hooks/ # useCreateFlow, useUserFlows, useDeposit
│ │ └── config/ # Contract ABIs, addresses, templates
│ └── server/ # Hono + Prisma + PostgreSQL
│ └── src/
│ ├── routes/ # REST API for events & subscriptions
│ └── services/ # Event indexer, subscription manager, DB
Single-contract design combining the flow registry and execution engine. Key design decisions:
- Trigger indexing via
keccak256(eventSig, emitter)for O(1) flow lookup - Topic filtering with
bytes32[3]wildcards (bytes32(0)= match any) - Deposit system so users pre-fund token transfers and swaps
- ReentrancyGuard on all deposit/withdraw operations
- Max 10 flows per trigger to bound gas costs in
_onEvent()
- Event Indexer — polls the chain for
FlowExecuted/AlertEmittedevents, persists to PostgreSQL - Subscription Manager — creates Reactivity subscriptions on-demand via
@somnia-chain/reactivitySDK - SSE Streaming — real-time event push to the frontend via Server-Sent Events
- Prisma 7 with
@prisma/adapter-pgfor PostgreSQL schema isolation
- 4-step flow builder — Trigger → Condition → Action → Review
- Template library — Whale Alert, Price Guardian, Cross-Contract, Smart DCA
- Real-time dashboard — execution history with live SSE updates
- Deposit management — approve, deposit, and withdraw ERC-20 tokens
- Wallet integration — RainbowKit + wagmi + viem
- Node.js >= 18
- pnpm
- PostgreSQL database
pnpm install# packages/contracts/.env
PRIVATE_KEY=0x...
# packages/server/.env
DATABASE_URL="postgresql://user:pass@localhost:5432/reactiveflow"
PRIVATE_KEY=0x...
REACTIVE_FLOW_ADDRESS=0x3d0504bbf7a41138da1a48e84accb1ab393d2b3fpnpm build:contracts
pnpm deploycd packages/server
pnpm exec prisma db push# From root — starts both frontend and backend
pnpm dev- Frontend: http://localhost:5173
- Backend API: http://localhost:3001
| Contract | Address |
|---|---|
| ReactiveFlow | 0x3d0504bbf7a41138da1a48e84accb1ab393d2b3f |
| Reactivity Precompile | 0x0000000000000000000000000000000000000100 |
| DIA Oracle V2 | 0xbA0E0750A56e995506CA458b2BdD752754CF39C4 |
| Method | Path | Description |
|---|---|---|
| GET | /api/health |
Health check |
| GET | /api/events |
List indexed events (supports ?limit, ?offset, ?flowId) |
| GET | /api/events/stream |
SSE stream for real-time events |
| GET | /api/subscriptions |
List all Reactivity subscriptions |
| POST | /api/subscriptions |
Create a new subscription |
| DELETE | /api/subscriptions/:id |
Remove a subscription |
| Layer | Technology |
|---|---|
| Smart Contracts | Solidity 0.8.20, Hardhat 3, OpenZeppelin, viem |
| Frontend | React 18, Vite, TailwindCSS, shadcn/ui, wagmi, RainbowKit |
| Backend | Hono, Prisma 7, PostgreSQL, viem |
| Reactivity | @somnia-chain/reactivity SDK, Reactivity Precompile |
| Monorepo | pnpm workspaces |
# Run contract tests
pnpm test:contractsMIT
