Releases: pinax-network/substreams-js
Releases · pinax-network/substreams-js
v0.7.0
v2
updates
⭐ New Updates
- Uses RPC V2 (
rpc.v2.service.proto
) - new param
finalBlocksOnly
(replacesforkSteps
)
emitters
output: (output: MapModuleOutput, clock: Clock) => void;
debugStoreOutputs: (output: StoreModuleOutput[], clock: Clock) => void;
debugMapOutputs: (output: MapModuleOutput[], clock: Clock) => void;
finalBlockHeight: (block_height: bigint, clock: Clock) => void;
❌ Deprecated
- Substreams RPC V1 removed
emitters
mapOutput: (output: MapModuleOutput, clock: Clock) => void;
debugStoreDeltas: (output: StoreDelta, clock: Clock) => void;
v0.6.0
New Features
// add single param (defaults to current `outputModule`)
substreams.param("to=swap.defi&symcode=EOS");
// add single param to specified map module
substreams.param("to=swap.defi&symcode=EOS", "map_transfers");
// add params to various map modules
substreams.params({map_transfers: "to=swap.defi&symcode=EOS"});
substreams.start();
Tested with latest eosio.token
substreams
Example: https://github.com/pinax-network/substreams-js/blob/main/examples/eosio.token.ts
What's Changed
- Support substreams with parameters by @Krow10 in #13
New Contributors
- @Krow10 made their first contribution in #13
Full Changelog: v0.5.0...v0.6.0
v0.5.0
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
v0.1.2
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