Reactivity
Run your contractthe moment an event lands
On Somnia, a contract can subscribe to onchain events. When one fires, the contract's handler runs in the same block, so nothing waits on a keeper or a bot.
Read the docsBlock460,660,802
Finalised
emits QuestionDue(42)
matches the subscription filter
+ one scheduled for this block
one block, about 100 ms, finalised together
- EventQuestionDue(42)Emitted by a user transaction
- SubscriptionTopic and emitter filterOwner holds at least 32 SOMI
- ReactionSynthetic transactionNormal receipt, logs and gas
Keepers, retired. Reactions, onchain.
What changes when automation is part of chain execution rather than a service you run beside it.
Retire the keeper infrastructure
Liquidations, scheduled settlement and upkeep run as contract handlers, not as off-chain bots that must stay online and funded.
React in the same block
Handlers execute after the block's user transactions, so a reaction lands in the same 100 ms block as the event that caused it. Further details can be found here.
Guarantee the effect is public
Reactive transactions appear on the explorer with normal receipts and logs, so every automated action is as auditable as a manual one.
For operators who need automation they can audit.
Three common patterns, each shown as the subscription that drives it.
01 · Settlement
Settle on schedule, every time
Schedule a handler at a block, an epoch or a timestamp to release escrow, roll a position or settle a market.
SubscriptionActive- Trigger
- Schedule
- At
- Timestamp, 18:00 UTC
- Handler
- settle(marketId)
- Effect
- Escrow released, in block
02 · Upkeep
Keep contracts current, every epoch
Subscribe to protocol events such as epoch boundaries for regular upkeep.
SubscriptionActive- Trigger
- System event
- Filter
- Epoch boundary
- Handler
- upkeep()
- Effect
- Runs once per epoch
03 · Resolution
Wake an oracle at resolution time
Somnia Oracle uses Reactivity to dispatch agent committees the moment a question is due.
SubscriptionActive- Trigger
- Schedule
- At
- Question due time
- Handler
- dispatchCommittee(id)
- Effect
- Committee starts work
How onchain reactivity works.
- Type
- Reactive · synthetic
- Block
- 460,660,802
- Handler
- MyHandler · 0x7a3f…c210
- Triggered by
- QuestionDue(42)
- Status
- Success
Handler from the onchain reactivity docs. Receipt values are illustrative.
For developers
Onchain or offchain. One way to subscribe.
Run the reaction inside the chain, or push the event to your app. Both start from the same subscription filters.
01 · Onchain
Handlers that are part of chain execution
Inherit SomniaEventHandler, set a filter and subscribe through the precompile. The owning contract pays the gas.
- Filter on topics, origin or emitter
- One-shot schedules at a block, epoch or timestamp
- @somnia-chain/reactivity-contracts
02 · Offchain
Push events to your app over WebSocket
Subscribe once through the node API and receive events with simulated read results in the same message.
- Events and simulated reads in one message
- Delivered over WebSocket
- TypeScript SDK for clients
Capabilities. What Reactivity gives you.
- 01
Event subscriptions
Filter on event topics, transaction origin or emitting contract.
- 02
Scheduled triggers
One-shot subscriptions at a block, an epoch or a timestamp.
- 03
System events
Subscribe to protocol events such as epoch boundaries for regular upkeep.
- 04
Priority ordering
Handlers are queued by priority fee, so time-critical reactions run first.
- 05
WebSocket push
Offchain subscriptions deliver events and simulated reads to clients with minimal latency.
- 06
Solidity and TypeScript packages
@somnia-chain/reactivity-contracts for handlers, and a TypeScript SDK for clients.
Get started
Automate without operating bots.
Start with the onchain reactivity quickstart, or talk to the team about moving keeper workloads onto Somnia.