Releases: substreams-js/substreams-node
Releases · substreams-js/substreams-node
v0.2.2
- Added new case in BlockEmitter for
session
event
Example
emitter.on("session", (session) => {
console.dir(session);
});
Output
SessionInit {
traceId: '247f5d94c8f07555eaec0a44a6553168',
resolvedStartBlock: 17381140n,
linearHandoffBlock: 17381143n,
maxParallelWorkers: 10n
}
Type
export class SessionInit extends Message<SessionInit> {
/**
* @generated from field: string trace_id = 1;
*/
traceId = "";
/**
* @generated from field: uint64 resolved_start_block = 2;
*/
resolvedStartBlock = protoInt64.zero;
/**
* @generated from field: uint64 linear_handoff_block = 3;
*/
linearHandoffBlock = protoInt64.zero;
/**
* @generated from field: uint64 max_parallel_workers = 4;
*/
maxParallelWorkers = protoInt64.zero;
constructor(data?: PartialMessage<SessionInit>) {
super();
proto3.util.initPartial(data, this);
}
static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "sf.substreams.rpc.v2.SessionInit";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "trace_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "resolved_start_block", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
{ no: 3, name: "linear_handoff_block", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
{ no: 4, name: "max_parallel_workers", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
]);
}
v0.2.1
- add
stop
method to stop Substreams process
// Stream Blocks
emitter.on("anyMessage", (message, cursor, clock) => {
console.dir(message);
console.dir(cursor);
console.dir(clock);
emitter.stop(); // stop streaming process
});
v0.2.0
What's Changed
- add new event listeners types
- once
- removeListener
- removeAllListeners
- eventNames
- getMaxListeners
- listenerCount
emitter.once("cursor", cursor => {
- add new
clock
emitter
emitter.on("clock", clock => {
const headers = new Headers({ "User-Agent": "@substreams/node" });
const transport = createDefaultTransport(baseUrl, token, registry, headers);
- Emit cursor last #2
Full Changelog: v0.1.4...v0.2.0
v0.1.5
What's Changed
Full Changelog: v0.1.4...v0.1.5
v0.1.4
- Make
token
optional field and does not include interceptor if none is provided
v0.1.3
- use
setTimeout
fromnode:timers/promises
- add
start(delay)
in milliseconds
v0.1.2
- fix: add
cursor
&clock
to events - feat: add Typescript declaration source maps
v0.1.1
@substreams/node
Substreams for
Node.js
Install
npm install @substreams/node
import()
function. Please don't open issues for questions regarding CommonJS / ESM.
Examples
import { createRegistry, createRequest } from "@substreams/core";
import { BlockEmitter, createDefaultTransport, readFileSyncSubstream } from "@substreams/node";
// auth API token
// https://app.streamingfast.io/
if (!process.env.SUBSTREAMS_API_TOKEN) {
throw new Error("SUBSTREAMS_API_TOKEN is require");
}
const token = process.env.SUBSTREAMS_API_TOKEN;
const baseUrl = "https://mainnet.eth.streamingfast.io:443";
// User parameters
const manifest = "./examples/subtivity-ethereum.spkg";
const outputModule = "map_block_stats";
const startBlockNum = 17381140;
const stopBlockNum = "+3";
// Read Substream
const substreamPackage = readFileSyncSubstream(manifest);
// Connect Transport
const registry = createRegistry(substreamPackage);
const transport = createDefaultTransport(baseUrl, token, registry);
const request = createRequest({
substreamPackage,
outputModule,
startBlockNum,
stopBlockNum,
productionMode: true,
});
// NodeJS Events
const emitter = new BlockEmitter(transport, request, registry);
// Stream Blocks
emitter.on("anyMessage", (message, state) => {
console.dir(message);
console.dir(state);
});
emitter.start();