Docs

Concepts / Somnia Blockchain

On-Chain Reactivity

Blockchains have historically had a major limitation: they are passive. They are excellent ledgers, but they are deaf and mute until a user kicks them into action with a transaction. A smart contract cannot "wake up" when a price changes, specific data shows up or when a specific event occurs.

The Usability

Imagine the world where you can instantly react to events happening on blockchain:

  • DeFi: Automated responses to price changes, liquidations, or interest accruals. For instance, a lending protocol might need to adjust collateral requirements instantly based on market volatility.
  • Gaming: Real-time updates for player achievements, in-game economies, or multiplayer interactions. Imagine a blockchain game where earning an NFT trophy automatically triggers rewards or level-ups without off-chain servers.
  • Business Logic: Supply chain tracking where an item's arrival (logged as an event) auto-initiates payments or audits. Or in insurance, a smart contract that pays out claims upon verified on-chain data like weather reports.

The Setup

The blockchain is ledger of transaction modifying the common state. Some of these transaction might emit a log, which is defined as an observable event:

User        -> Blockchain : Submit transaction
Blockchain  -> Event log  : Event emitted

Event log: observable event

Traditionally the developer would need to create an infrastructure that constantly monitors the blockchain state and event through RPC calls. Then based on the logic the custom app would create a transaction and post it for the inclusion at the next available block:

User              -> Blockchain        : Transaction
Blockchain        -> Event log         : Event emitted

Loop, constant polling:
  Off-chain monitor -> Blockchain        : RPC call
  Blockchain        -> Off-chain monitor : Current state

Off-chain monitor -> Custom app logic  : Event detected
Custom app logic  -> Custom app logic  : Process logic
Custom app logic  -> Blockchain        : Submit reaction tx

Off-chain monitor: custom infrastructure
Blockchain: reaction included in the NEXT available block

As expected this created a large overhead for a typical development team. Additionally it did not meet the requirements of decentralisation, trustlessness, immediate reaction and reliable event handling.

This is why we saw a plethora of services known as indexers or Web3 hooks:

User                -> Blockchain          : Transaction
Blockchain          -> Event log           : Event emitted

Indexer service     -> Blockchain          : Monitor events
Blockchain          -> Indexer service     : Event data
Indexer service     -> Custom config/logic : Trigger hook
Custom config/logic -> Custom config/logic : Execute logic
Custom config/logic -> Blockchain          : Submit reaction tx

Indexer service: centralized and trusted
Blockchain: reaction included in the NEXT available block

They alleviate a lot of issues related to the infrastructure, at the same time they add new issues related to the domain-specific configuration or language. Still the key requirements are still not met:

  • indexers are centralised and trustfull
  • the event handling trasaction can only be included in the next available block
  • it is not MEV-resistant
  • it's only as reliable as the indexer provider

The Solution

Enter Somnia Native On-Chain Reactivity.

This isn't just an incremental improvement; it's a paradigm shift that enables real-time, trustless and decentralised reactions without relying on external systems:

User              -> Somnia blockchain : Transaction
Somnia blockchain -> Event log         : Event emitted
Event log         -> Event handler     : Trigger handler
Event handler     -> Event handler     : Execute reaction logic

Somnia blockchain: same block execution
Event handler: decentralized and trustless
Event handler: MEV-resistant

The Benefits

Once an event is defined, it's handling is happening automatically by blockchain nodes:

  • Real-Time: Reaction usually included in the same block. See limits.
  • Decentralised: As decentralised as the blockchain itself.
  • Trustlessness: No trusted party required.
  • MEV: Fully MEV-resistant due to deterministic inclusion of event handlers
  • Developer-Friendly: Familiar paradigms (e.g., subscriptions akin to event listeners in traditional programming) and interface reduce complexity.
  • Cost Efficiency: Optimized gas usage minimize expenses compared to infrastucture required for constant off-chain monitoring.
  • Security and Resilience: Backed by the blockchain itself. Reduces attack surfaces by eliminating external dependencies; nested events allow complex chains without intermediaries.
  • Scalability: Supports high-throughput apps, as seen in Somnia's 1M+ TPS capability, making it ideal for mass-adoption scenarios.

Comparison Table

Aspect Traditional RPC Indexer/Hooks Somnia Reactivity
Timing Next block Next block Same block, unless the per-block reactivity limits defer it
Decentralization Developer infra Centralized service Fully decentralized
Trust Model Self-hosted Trusted third party Trustless
MEV Resistance ❌ ❌ ✅
Infrastructure High complexity Medium complexity Zero external infra
Reliability Self-managed Service-dependent Blockchain-native

Send feedback

Agents: POST the same to /api/feedback.