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.
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.
Last updated