Skip to main content
Example code snippets to stream from the indexer for explorer module related data using StreamManagerV2.

Using gRPC Stream with StreamManagerV2

Stream blocks

import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
import { 
  StreamManagerV2,
  IndexerGrpcExplorerStreamV2 
} from '@injectivelabs/sdk-ts/client/indexer'

const endpoints = getNetworkEndpoints(Network.Testnet)
const stream = new IndexerGrpcExplorerStreamV2(endpoints.indexer)

const streamManager = new StreamManagerV2({
  id: 'explorer-blocks',
  streamFactory: () => stream.streamBlocks({
    callback: (response) => {
      streamManager.emit('data', response)
    }
  }),
  onData: (blocks) => {
    console.log(blocks)
  },
  retryConfig: { enabled: true }
})

streamManager.on('connect', () => console.log('Stream connected'))
streamManager.start()

Stream blocks with transactions

import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
import { 
  StreamManagerV2,
  IndexerGrpcExplorerStreamV2 
} from '@injectivelabs/sdk-ts/client/indexer'

const endpoints = getNetworkEndpoints(Network.Testnet)
const stream = new IndexerGrpcExplorerStreamV2(endpoints.indexer)

const streamManager = new StreamManagerV2({
  id: 'explorer-blocks-with-txs',
  streamFactory: () => stream.streamBlocksWithTxs({
    callback: (response) => {
      streamManager.emit('data', response)
    }
  }),
  onData: (blocksWithTransactions) => {
    console.log(blocksWithTransactions)
  },
  retryConfig: { enabled: true }
})

streamManager.on('connect', () => console.log('Stream connected'))
streamManager.start()

Stream transactions

import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
import { 
  StreamManagerV2,
  IndexerGrpcExplorerStreamV2 
} from '@injectivelabs/sdk-ts/client/indexer'

const endpoints = getNetworkEndpoints(Network.Testnet)
const stream = new IndexerGrpcExplorerStreamV2(endpoints.indexer)

const streamManager = new StreamManagerV2({
  id: 'explorer-transactions',
  streamFactory: () => stream.streamTransactions({
    callback: (response) => {
      streamManager.emit('data', response)
    }
  }),
  onData: (transactions) => {
    console.log(transactions)
  },
  retryConfig: { enabled: true }
})

streamManager.on('connect', () => console.log('Stream connected'))
streamManager.start()