v0.3.0
New Features
- set host as default (optional) uses StreamingFast ETH mainnet
- set default
startBlock=0
- improve stopBlock handling (allows
"+100"
) - replace
example.js
using ETH using Subtivity substream - get authentication token using StreamingFast issue endpoint
Substreams
Javascript consumer
Substream
Javascript consumer library using Node.js Event emitters.
Install
Using NPM:
npm install --save substreams
or using Yarn:
yarn add substreams
Requirements
Endpoints
Quickstart
const { Substreams, download } = require("substreams");
// User input
const spkg = "https://github.com/pinax-network/subtivity-substreams/releases/download/v0.1.0/subtivity-ethereum-v0.1.0.spkg";
const outputModule = "map_block_stats";
const startBlockNum = "300000";
const stopBlockNum = "+10";
// Initialize Substreams
const substreams = new Substreams(outputModule, {
startBlockNum,
stopBlockNum,
authorization: process.env.STREAMINGFAST_KEY // or SUBSTREAMS_API_TOKEN
});
(async () => {
// download Substream from IPFS
const {modules, registry} = await download(spkg);
// Find Protobuf message types from registry
const BlockStats = registry.findMessage("subtivity.v1.BlockStats");
if ( !BlockStats) throw new Error("Could not find BlockStats message type");
substreams.on("mapOutput", output => {
const decoded = BlockStats.fromBinary(output.data.mapOutput.value);
console.log(decoded);
});
// start streaming Substream
await substreams.start(modules);
// end of Substream
console.log("done");
process.exit();
})();
Tests
$ npm ci
$ npm test