Somnia Reactivity
Somnia Reactivity
Reactivity lets applications respond to on-chain events without running a polling loop. It's one of Somnia's standout features.
Somnia provides reactivity in two complementary forms:
On-chain reactivity stores persistent event subscriptions in chain state and then executes contract handlers when matching events are committed. The reaction is part of chain execution.
Off-chain reactivity is a WebSocket feature served by the node API. A client subscribes once, receives pushed events, and can ask the node to run read-only simulations for each event so that derived state arrives in the same message — minimising latency. The reaction stays in the client.
Both forms of reactivity are live on the Global mainnet and testnet and on the Tokyo Subchain mainnet and testnet.
Which one to use
Use on-chain reactivity when the reaction should be part of chain execution, i.e. a guaranteed, public effect. For example: automatic token rebalancing, scheduled settlement, or a callback that must fire even if the original owner is offline.
Use off-chain reactivity when the reaction should stay in your app. For example: a UI that updates when an event lands, an indexer that writes to a database, or a bot that watches a pool. Off-chain subscriptions are more flexible and don't require spending SOMI.
The two kinds of reactivity are independent. You can use both at once.
See it in use
- Reactivity in Somnia Explorer. Handler executions and subscription changes as they happen, and a lookup for any subscription; Tokyo for the Tokyo Subchain.
- Somnia Price Feeds. Its scheduler is a reactivity handler on a schedule subscription that re-arms itself every tick.
Use it from the CLI and MCP
The Somnia CLI watches reactivity but can't create a subscription: use the SDK or a contract, as in the tutorials.
somnia watch reactivity --emitter $CONTRACT --network testnet # off-chain pushes over WebSocket
somnia watch logs --address $CONTRACT --network testnet # a contract's logs as blocks arrive
The MCP server has no reactivity tool.