Skip to content

Releases: substreams-js/substreams-node

v0.2.2

18 Sep 18:32
Compare
Choose a tag to compare
  • 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

06 Sep 15:50
Compare
Choose a tag to compare
  • 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

02 Aug 02:38
Compare
Choose a tag to compare

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 => {
  • remove setTimeout delay on start()
  • Added headers interceptor to grpc transport by @chamorin in #3
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

01 Aug 19:08
Compare
Choose a tag to compare

What's Changed

  • Added headers interceptor to grpc transport by @chamorin in #3
  • Emit cursor last #2

Full Changelog: v0.1.4...v0.1.5

v0.1.4

12 Jul 21:58
Compare
Choose a tag to compare
  • Make token optional field and does not include interceptor if none is provided

v0.1.3

07 Jun 14:52
Compare
Choose a tag to compare
  • use setTimeout from node:timers/promises
  • add start(delay) in milliseconds

v0.1.2

02 Jun 19:26
Compare
Choose a tag to compare
  • fix: add cursor & clock to events
  • feat: add Typescript declaration source maps

v0.1.1

31 May 21:34
Compare
Choose a tag to compare

@substreams/node

Build Status npm version License Try substreams on RunKit

Substreams for Node.js

Install

npm install @substreams/node

⚠️Warning: This package is native ESM. If your project uses CommonJS, you'll have to convert to ESM or use the dynamic 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();