Overview

Laserstream’s gRPC offering builds on a Yellowstone-based interface and enhances it with features like historical replay, multi-node failover, and a fully managed environment. You can connect either directly with @yellowstone-grpc or use the higher-level Helius Laserstream client for added benefits (auto-reconnect, subscription management, error handling, etc.).

Quickstart

1

Create a New Project

mkdir laserstream-grpc-demo
cd laserstream-grpc-demo
npm init -y
2

Install Dependencies

npm install helius-laserstream
npm install --save-dev typescript ts-node
npx tsc --init
3

Obtain Your API Key

Generate a key from the Helius Dashboard.

4

Create a Subscription Script

Create index.ts with the following:

import { subscribe, CommitmentLevel, LaserstreamConfig, SubscribeRequest } from 'helius-laserstream'

async function main() {
  const subscriptionRequest: SubscribeRequest = {
    transactions: {
      client: {
        accountInclude: ['TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'],
        accountExclude: [],
        accountRequired: [],
        vote: false,
        failed: false
      }
    },
    commitment: CommitmentLevel.CONFIRMED,
    accounts: {},
    slots: {},
    transactionsStatus: {},
    blocks: {},
    blocksMeta: {},
    entry: {},
    accountsDataSlice: [],
    // Optionally, you can replay missed data by specifying a fromSlot:
    // fromSlot: '224339000'
    // Note: Currently, you can only replay data from up to 3000 slots in the past.
  };

// Replace the values below with your actual Laserstream API key and endpoint
const config: LaserstreamConfig = {
  apiKey: 'YOUR_API_KEY', // Replace with your key from https://dashboard.helius.dev/
  endpoint: 'YOUR_ENDPOINT', // Replace with your endpoint from https://dashboard.helius.dev/
}

  await subscribe(config, subscriptionRequest, async (data) => {
    
    console.log(data);

  }, async (error) => {
    console.error(error);
  });
}

main().catch(console.error);
5

Replace Your Endpoint and API Key

In index.ts, update the config object with the actual apiKey and endpoint from your Helius Dashboard:

const config: LaserstreamConfig = {
  apiKey: 'YOUR_ACTUAL_API_KEY', // Replace with your key
  endpoint: 'YOUR_ACTUAL_ENDPOINT', // Replace with your endpoint
}
6

Run and View Results

npx ts-node index.ts

Whenever a confirmed token transaction involves TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA, you’ll see the data in your console.

Subscribe Request

In the subscribe request, you need to include the following general parameters:

Historical Replay: You can optionally include a fromSlot: string field in the main SubscribeRequest object to replay data from a specific slot onwards. Currently, replay is supported for up to 3000 slots in the past.

const subscriptionRequest: SubscribeRequest = {
  commitment: CommitmentLevel.CONFIRMED,
  accountsDataSlice: [],
  transactions: {},
  accounts: {},
  slots: {},
  blocks: {},
  blocksMeta: {},
  entry: {},
}

Next, you’ll need to specify the filters for the data you want to subscribe to, such as accounts, blocks, slots, or transactions.

Code Examples

import { subscribe, CommitmentLevel, LaserstreamConfig, SubscribeRequest } from 'helius-laserstream'

async function main() {
  const subscriptionRequest: SubscribeRequest = {
    transactions: {},
    commitment: CommitmentLevel.CONFIRMED,
    accounts: {},
    slots: {
      slot: { filterByCommitment: true },
    },
    transactionsStatus: {},
    blocks: {},
    blocksMeta: {},
    entry: {},
    accountsDataSlice: [],
  }


 const config: LaserstreamConfig = {
    apiKey: 'YOUR_API_KEY', // Replace with your key
    endpoint: 'YOUR_ENDPOINT', // Replace with your endpoint
  }

  await subscribe(config, subscriptionRequest, async (data) => {
    console.log(data);
  }, async (error) => {
    console.error(error);
  });
}

main().catch(console.error);

Troubleshooting / FAQ