A demux-js Action Reader Implementation for dfuse.io
demux-js-dfuse
implements an ActionReader for demux-js to allow for sourcing blockchain events to deterministically update queryable datastores and trigger side effects.
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.
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 to1
. 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 tofalse
. If set totrue
, only irreversible blocks will be fetchedquery: string
. Optional. Defaults tostatus: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()
All tests are run using Jest. Use yarn test
to run them.
- Thanks to @flux627 for the great work on demux-js!