Skip to content

v0.1.2

Compare
Choose a tag to compare
@DenisCarriere DenisCarriere released this 19 Dec 17:13
· 77 commits to main since this release

Substreams Node.js consumer

Substream consumer library using native Node.js event emitters.

Requirements

Quickstart

import { Substreams, download } from "substreams";

// User input
const host = "eos.firehose.eosnation.io:9001";
const substream = "QmXhHkjuqCFvxEaYDrcURZMhD7y9RNSfNWmXHtX8ramEHL";
const proto = "QmWthaEr1Zde3g7CdoWpPqL4fCvptHZHFq4evBNoWppotP";
const outputModules = ["map_transfers"];
const startBlockNum = "283000000";
const stopBlockNum = "283001000";

// Initialize Substreams
const substreams = new Substreams(host, {
    startBlockNum,
    stopBlockNum,
    outputModules,
});

(async () => {
    // download Substream & Protobuf from IPFS
    const [modules, root] = await download(substream, proto);

    // Protobuf types
    const Action = root.lookupType("Action");

    substreams.on("block", block => {
        console.log("Block:", block);
    });
    
    substreams.on("mapOutput", output => {
        if ( output.name == "map_transfers" ) {
            const action = Action.decode(output.data.mapOutput.value);
            console.log("Map Output:", action);
        }
    });

    substreams.on("storeDeltas", output => {
        console.log("Store Deltas:", output);
    });

    await substreams.start(modules);
    console.log("done");
    process.exit();
})();

Tests

$ npm ci
$ npm test