@aloxide/demux

Implement demux pattern for sync data from blockchain to a centralized database

Usage no npm install needed!

<script type="module">
  import aloxideDemux from 'https://cdn.skypack.dev/@aloxide/demux';
</script>

README

Table of content

Package @aloxide/demux

Implement demux pattern for sync data from blockchain to a centralized database.

Usage

real samples

ExpressActionWatcher: Exposes the API methods from the BaseActionWatcher through an Express server.

const expressWatcher = new ExpressActionWatcher(
  actionReader,
  actionHandler,
  pollInterval,
  portNumber,
);

expressWatcher.listen();

Now you can start watching for block data by making POST /start request, and to stop receiving block data by making POST /pause request. Between these requests, actionReader will read block data from the blockchain and passing it to actionHandler.

AloxideActionWatcher: A ready-to-use action watcher with ability to get only one block per request e.g. using in a lambda function.

Call watchOnce to read data of only one block (specified by startAtBlock option), for example when you want to read the blockchain once per lambda invocation.

const actionWatcher = new AloxideActionWatcher(actionReader, actionHandler, 1000);
await actionWatcher.watchOnce(); // `actionHandler` will be run once