Typescript

TypeScript/Node.js client for ThorStreamer using gRPC-js.

Installation

Install dependencies
npm install @grpc/grpc-js google-protobuf

Proto Generation

1

Clone repository

# Clone the repository
git clone https://github.com/thorlabsDev/ThorStreamer.git
cd ThorStreamer/examples/typescript
2

Install dependencies

# Install dependencies
npm install
3

Generate proto files

# Generate proto files
npm run proto:gen
npm run proto:ts

Quick Start

Quick start example
import * as grpc from '@grpc/grpc-js';
import { Empty } from 'google-protobuf/google/protobuf/empty_pb';
import { EventPublisherClient } from './proto/publisher_grpc_pb';
import { StreamResponse } from './proto/publisher_pb';

const client = new EventPublisherClient(
    process.env.SERVER_ADDRESS!,
    grpc.credentials.createInsecure()
);

const metadata = new grpc.Metadata();
metadata.set('authorization', process.env.AUTH_TOKEN!);

const stream = client.subscribeToTransactions(new Empty(), metadata);

stream.on('data', (response: StreamResponse) => {
    console.log('Transaction:', response.getData().length, 'bytes');
});

stream.on('error', (err) => {
    console.error('Stream error:', err);
});

stream.on('end', () => {
    console.log('Stream ended');
});

API Reference

Creating a Client

subscribeToTransactions

subscribeToSlotStatus

subscribeToWalletTransactions

Monitor up to 10 wallet addresses:

subscribeToAccountUpdates

Monitor accounts with optional owner filtering:

Error Handling

Promise Wrapper

Wrap streams in Promises for async/await usage:

Full Example

See the complete implementation with proto generation scripts in the repository:

  • https://github.com/thorlabsDev/ThorStreamer/tree/master/examples/typescript

Build Scripts

Package.json scripts (descriptions shown in place of generator commands):

Resources

Last updated