Typescript
TypeScript/Node.js client for ThorStreamer using gRPC-js.
Installation
npm install @grpc/grpc-js google-protobufProto Generation
1
Quick Start
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