10. Events and Event Queries

The Ethereum blockchain has a concept called events, also referred to as transaction logs, which are used to indicate that a specific action has taken place within a smart contract. The Ethereum blockchain is eventually consistent, and transactions sent to the blockchain are only considered to have been processed once they have been included into a block.

Without transactions, an application built on top of Ethereum would have to check the updated state of the blockchain vs. the previous state, on every new block. This is untenable if there are more than a few values to watch. For example, if there are 100,000 user accounts, on each new block an application would have to query its smart contract on the order of 100,000 times to see if anything changed. With events, the application can simply subscribe to any events that a particular address is issuing, and take action on those specific events. For example, updating a UI.

However, even with events a DApp still needs to maintain its own state. Additionally, there are corner cases to handle. Events can be undone if a transaction that emitted an event is part of a block that is no longer considered part of the blockchain due to a chain reorganization. If the DApp loses its connection to its Ethereum node, it may miss interim events and need to perform a delta between the events it knows about and the events missed during the connection interruption to the node. MultiBaas handles event caching and caching on behalf of DApps, exposing events via the REST API.

MultiBaas also offers the ability to query and compute aggregations of the event data. It offers a flexible system for specifying event queries, and then running event data through them to produce customized views of the event data.