02StreamingIndexerExplorer - InjectiveLabs/injective-ts GitHub Wiki

:warning: The Docs have been moved to https://docs.ts.injective.network/querying/querying-api/streaming/streaming-indexer-explorer :warning:

Example code snippets to stream from the indexer for explorer module related data.

Using gRPC Stream

  • stream blocks
import { IndexerGrpcExplorerStream } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";

const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const indexerGrpcExplorerStream = new IndexerGrpcExplorerStream(
  endpoints.indexer
);

const streamFn = indexerGrpcExplorerStream.blocks.bind(
  indexerGrpcExplorerStream
);

const callback = (blocks) => {
  console.log(blocks);
};

const streamFnArgs = {
  callback,
};

streamFn(streamFnArgs);
  • stream blocks with transactions
import { IndexerGrpcExplorerStream } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";

const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const indexerGrpcExplorerStream = new IndexerGrpcExplorerStream(
  endpoints.indexer
);

const streamFn = indexerGrpcExplorerStream.blocksWithTxs.bind(
  indexerGrpcExplorerStream
);

const callback = (blocksWithTransactions) => {
  console.log(blocksWithTransactions);
};

const streamFnArgs = {
  callback,
};

streamFn(streamFnArgs);
  • stream transactions
import { IndexerGrpcExplorerStream } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";

const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const indexerGrpcExplorerStream = new IndexerGrpcExplorerStream(
  endpoints.indexer
);

const streamFn = indexerGrpcExplorerStream.streamTransactions.bind(
  indexerGrpcExplorerStream
);

const callback = (transactions) => {
  console.log(transactions);
};

const streamFnArgs = {
  callback,
};

streamFn(streamFnArgs);