Skip to content

02StreamingAPI

Bojan Angjelkoski edited this page Mar 5, 2023 · 8 revisions

Streaming from Accounts Module

Using gRPC

Example code snippets to stream the accounts module on the chain using the gRPC protocol.

  • Streaming accounts balances
import { IndexerGrpcAccountApi, IndexerGrpcAccountStream } from "@injectivelabs/sdk-ts"
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";

const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const injectiveAddress = 'inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku'
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer)
const indexerGrpcAccountStream = new IndexerGrpcAccountStream(endpoints.indexer)

const [subaccountId] = await indexerGrpcAccountApi.fetchSubaccountsList(
  injectiveAddress
);

await indexerGrpcAccountStream.streamSubaccountBalance({
  subaccountId,
  callback: (subaccountBalance) => {
    console.log(subaccountBalance);
  },
  onEndCallback: (status) => {
    console.log("Stream has ended with status: " + status);
  },
});

⚠️ DOCUMENTATION ⚠️

Clone this wiki locally