Skip to content

Latest commit

 

History

History
85 lines (56 loc) · 3.58 KB

README.md

File metadata and controls

85 lines (56 loc) · 3.58 KB

demux-js-dfuse

A demux-js Action Reader Implementation for dfuse.io


Status GitHub Issues GitHub Pull Requests License


📝 Table of Contents

🧐 About

demux-js-dfuse implements an ActionReader for demux-js to allow for sourcing blockchain events to deterministically update queryable datastores and trigger side effects.

🏁 Getting Started

To run a basic example, run this command:

yarn run:example

The code for the example can be found in the /example directory at the root of the project.

🛫 Usage

To use dfuse as your data source, simply pass a DfuseActionReader instance to a Demux ActionWatcher.

You will need to create your own ActionHandler. For more information on this, visit the demux-js repository.

It is critical that you set the ActionHandler's option validateBlocks to false. Because the dfuse API only returns the blocks that match your query, it means the chain of blocks passed through demux will be missing blocks. Without this option set, demux will not work.

To generate a dfuse API key, visit the dfuse website.

The DfuseActionReader class supports the following parameters:

  • dfuseApiKey: string. Required. An API key that can be obtained from the dfuse.io website.
  • startAtBlock: number. Optional. Defaults to 1. For positive values, this sets the first block that this will start at. For negative values, this will start at (most recent block + startAtBlock), effectively tailing the chain. Be careful when using this feature, as this will make your starting block dynamic.
  • onlyIrreversible: boolean. Optional. Defaults to false. If set to true, only irreversible blocks will be fetched
  • query: string. Optional. Defaults to status:executed. A dfuse SQE query. For more informations, see the docs.
import { BaseActionWatcher } from "demux"
import { ObjectActionHandler } from "./ObjectActionHandler"
import { handlerVersion } from "./handlerVersions/v1"
import { DfuseActionReader } from "demux-js-dfuse"

const actionHandler = new ObjectActionHandler([handlerVersion], { validateBlocks: false })

const dfuseActionReader = new DfuseActionReader({
  dfuseApiKey: "YOUR DFUSE API KEY",
  startAtBlock: 1,
  onlyIrreversible: false,
  query: "account:eosknightsio",
  network: "mainnet"
})

const actionWatcher = new BaseActionWatcher(dfuseActionReader, actionHandler, 100)
actionWatcher.watch()

🔧 Running the tests

All tests are run using Jest. Use yarn test to run them.

🎉 Acknowledgements

  • Thanks to @flux627 for the great work on demux-js!