EOSIO Toolkit Update: Demux v4.0
February 22nd, 2019
EOSIO Toolkit Update: Demux v4.0 — New RestAPI, Triggering Effect Confirmations, and more EOSIO Action Support
As a contributor to the development and enhancement of the EOSIO software, we are pleased to confirm a new stable release for Demux, v4.0 which greatly expands the features available in the library to developers building on EOSIO. You can find more detail about Demux in its GitHub repository.
One of the primary benefits of building on the EOSIO blockchain platform is the ability to create more usable, scalable, and flexible applications. While blockchain development can be difficult, one of the primary reasons developers are migrating to the EOSIO blockchain platform is its ease of use and parallels to familiar development practices used in nonblockchain development. Examples of this include familiar smart contract development languages like C++, flexible permissions systems, and a number of tools in development like EOSIO.CDT and Demux.
What is Demux?
In July last year, shortly after the release of EOSIO, we announced Demux, a new open-source development tool for the EOSIO community that simplifies complex blockchain application development.
If you aren’t already familiar, Demux is an open source library that provides a suggested architecture for creating a deterministic database off-chain that is verified by an EOSIO blockchain implementation. It draws inspiration from Facebook’s Flux Architecture pattern and Redux, creating a back-end infrastructure pattern for sourcing blockchain events in order to deterministically update queryable databases for applications built on the EOSIO blockchain.
This is incredibly powerful for application developers building on EOSIO because it allows you to use traditional Mongo or Postgres SQL databases in a way that makes the data stored in them verifiable by the blockchain. This practice enables the best of both worlds: the flexibility and speed of traditional databases, coupled with the trust and immutable properties of a blockchain.
Demux v4.0 Updates
There have been a number of updates in the past few months to the Demux library since it was released, but it has reached a point where it will start having its own release cycle independent of EOSIO core. We will continue to provide updates on its release schedule similar to the updates we provide each month for EOSIO as we continue to expand and strengthen functionality for Demux.
New Demux REST API
In Demux v4.0 we’ve introduced a new REST API that makes it easier to operate demux as a standalone environment. The REST API allows applications to interact with Demux using an endpoint — giving developers the ability to start / pause their Demux instance while making updates to better handle errors and introduce new functionality in their application without having to shut down the process. Prior to this update, if you wanted to modify your demux instance, you had to stop the service from running and make updates limiting the flexibility and speed at which you can update your application.
There are a number of changes you can read about in more detail in the release like the ExpressActionWatcher being used instead of the BaseActionWatcher which exposes an endpoint that allows you to start, pause, and get info about the running demux instance. We have also removed `maxHistoryLength` on AbstractActionReader — which allows for history length to be automatically optimized based on the last irreversible block. These updates make for a more robust development experience with Demux and enable new features which we will go into in more detail below.
Effect Triggers on Confirmation
One of the most useful features of Demux are Effects, the ability to trigger non-blockchain actions based on things that happen with blockchain data. For example, sending an email or pushing a notification when something is written to the blockchain.
While this has been always available through Effects, in Demux v4.0 we have extended this functionality to allow for Effects to be fired based on irreversible blocks, and not beforehand. Essentially the new functionality will keep a list in memory of effects that an application wants to run and when blocks become irreversible, it will execute the actions. This allows for more granular control in your development and definite confirmation that your action has been executed and written in stone on the blockchain before taking further action.
A simple example of where this is useful could be seen in a token transfer application where you want to notify a user that a transfer is pending and then moments later push a second notification that the transfer is confirmed.
Inline and Deferred EOSIO Actions in Demux
Finally, we have made a tighter integration with the MongoDB plugin for EOSIO using demux-js-eos that populates blocks with actions and transactions. The core of Demux is a mongo action reader that creates a deterministic off-chain database. This functionality has been extended to include inline and deferred actions.
The full details of the release can be viewed in the official GitHub repository for Demux. There are a number of breaking changes to be reviewed in more detail if you are using the Demux library in your application. The example library demux-js serves as a reference NodeJS implementation of Demux architecture.
If you are interested in providing feedback and working more closely with our team to improve the EOSIO software for developers, you can send our developer relations team an email at email@example.com.
You can also stay up to date on future updates by subscribing to our mailing list on the EOSIO Developer Portal. We are excited to be continually improving the usability of the software for EOSIO developers as we continue laying a foundation for the mass adoption of blockchain technology.