// TypeScript + Yellowstone gRPC
Stream Solana data with TypeScript.
TypeScript is the most popular language for Solana bot development. The official @triton-one/yellowstone-grpc package gives you type-safe access to real-time blockchain data. This tutorial walks through installation, connection, subscriptions, and production-ready error handling.
The standard Yellowstone client
@triton-one/yellowstone-grpc is the official TypeScript and Node.js client for the Yellowstone gRPC protocol, maintained by Triton One — the team behind the original Dragon's Mouth specification. It handles gRPC connection management, protobuf serialization, and stream lifecycle out of the box. You don't need to compile proto files, generate stubs, or manage gRPC channels manually. The package abstracts all of that into a clean, typed API.
TypeScript definitions are included with the package, giving you full IntelliSense coverage for every type in the protocol: SubscribeRequest, SubscribeUpdate, transaction filters, account filters, commitment levels, and all the nested message types. This means your IDE catches malformed subscription requests at compile time rather than at runtime — a significant advantage when you're iterating on complex filter configurations. Autocomplete alone saves hours of referencing proto definitions.
The client works with any Yellowstone-compatible gRPC endpoint. Whether you're connecting to QuickNode, Chainstack, Solana Tracker, or Subglow, the same @triton-one/yellowstone-grpc package handles the connection. You change the endpoint URL and authentication header — everything else stays identical. This portability means you can switch providers without rewriting your streaming logic, and you can test against different endpoints in development versus production.
Installation is a single npm command. The package pulls in the necessary gRPC dependencies (including the native @grpc/grpc-js module) automatically. No C++ compilation, no system-level dependencies — it works on Linux, macOS, and Windows out of the box.
Connect to an endpoint
The client constructor takes three arguments: the endpoint URL, an authentication token (or undefined if you pass credentials via metadata instead), and an options object for gRPC channel configuration. The most important option is grpc.max_receive_message_length, which controls the maximum size of inbound messages. Solana blocks can be large — especially when they contain many transactions — so setting this to 64 MB prevents unexpected stream terminations on high-throughput slots.
Authentication varies by provider. Most Yellowstone endpoints accept an x-token header, which the client sends automatically when you pass a token string as the second constructor argument. Subglow and some other providers use x-api-key instead — you can pass this via the metadata parameter when calling subscribe(). Either approach works; the difference is purely which header the provider expects.
Subscribe to transactions
Transaction subscriptions are the core of most Solana bots. You build a SubscribeRequest with a transactions filter that specifies which programs you want to track. The account_include array accepts program IDs — every transaction that touches one of these programs will be forwarded to your stream. For DeFi trading, the most common targets are Pump.fun (6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P), Raydium (675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8), and Jupiter (JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4).
Set vote: false and failed: false on your filter to eliminate noise. Validator vote transactions make up roughly half of Solana's throughput and are never relevant for DeFi. Failed transactions add volume without actionable data. Excluding both reduces your processing load dramatically and lets your bot focus on confirmed, successful trades.
Commitment level matters for your use case. Use CONFIRMED for trading bots where speed is critical — confirmed transactions are available within ~400ms of the slot. Use FINALIZEDfor high-value operations like large transfers or bridge transactions where you need the strongest guarantee that the transaction won't be rolled back.
Subscribe to accounts
Account subscriptions let you watch for state changes on specific accounts or all accounts owned by a particular program. This is fundamentally different from transaction subscriptions — instead of getting notified when a program is invoked, you get notified when an account's data changes, regardless of which program caused the change. This makes account subscriptions ideal for use cases like copy trading (watching whale wallets for balance changes), portfolio tracking (monitoring your own token accounts), and liquidation monitoring (watching margin accounts approaching liquidation thresholds).
You can filter accounts by owner — which gives you every account owned by a specific program — or by specific account public keys. Owner-based filters are broader: subscribing to the Token Program owner gives you updates for every SPL token account on Solana. Pubkey-based filters are precise: you specify exactly which accounts to watch. For most trading applications, you'll use pubkey filters to track known wallets or liquidity pool accounts.
For advanced filter patterns including combining transaction and account subscriptions, owner-based filters, and memcmp matching, see the Yellowstone gRPC filter guide.
Type-safe event handling
One of TypeScript's strongest advantages over raw JavaScript for Yellowstone gRPC is discriminated union types. The SubscribeUpdate type has optional fields for each kind of update — transaction, account, slot, block, ping, and pong. TypeScript narrows the type when you check which field is present, giving you full type safety on the nested data without manual casting. Your editor knows exactly what properties are available inside each branch, and the compiler catches access to properties that don't exist on the current update type.
For transaction updates, the key fields are transaction.transaction (the actual transaction data including signatures, message, and account keys), transaction.meta (execution metadata including pre/post balances, log messages, and inner instructions), and transaction.slot. Parsing the transaction means walking the message's compiled instructions, mapping program indices to account keys, and decoding instruction data using the target program's schema — typically Borsh for Solana programs.
Production error handling
gRPC streams are long-lived connections, and every long-lived connection will eventually disconnect. Network partitions, load balancer rotations, server deployments, and transient DNS failures all cause stream interruptions. A production TypeScript bot that doesn't implement reconnection logic will silently stop receiving data after the first interruption — and in trading, silent data gaps are expensive.
The standard approach is a reconnection wrapper with exponential backoff. When the stream emits an error or ends unexpectedly, you wait a short interval, then attempt to reconnect. If the reconnection fails, you double the wait interval up to a configurable maximum, preventing your client from flooding the server during an outage. Tracking the last processed slot gives you a resumption checkpoint — after reconnecting, you can detect gaps in the slot sequence and take corrective action.
Different gRPC error codes require different handling strategies. UNAVAILABLE is transient — retry with backoff. CANCELLED usually means the server closed the stream — reconnect immediately. DEADLINE_EXCEEDED means your timeout was too short — increase the deadline and retry. UNAUTHENTICATED is permanent — your API key is invalid and retrying won't help. Distinguishing between retryable and non-retryable errors prevents your bot from wasting cycles on reconnections that will never succeed.
Reset backoff on success
Set backoff to 1s on every successful event so transient hiccups recover instantly.
Track last processed slot
After reconnection, compare the incoming slot to lastSlot to detect and log data gaps.
Distinguish error codes
UNAVAILABLE = retry. UNAUTHENTICATED = stop. CANCELLED = reconnect immediately.
Set a max backoff ceiling
Cap exponential backoff at 30 seconds to avoid minutes-long waits during extended outages.
Subglow: same client, better output
Subglow is fully compatible with the Yellowstone gRPC protocol. You use the exact same @triton-one/yellowstone-grpc client you're already familiar with — no proprietary SDK, no additional npm packages, no new API to learn. The difference is in what comes back. When you subscribe through a standard Yellowstone endpoint, you receive raw protobuf messages containing binary transaction data that you need to deserialize, map accounts, parse instructions, and decode Borsh-encoded program data. When you subscribe through Subglow, you receive the same gRPC stream, but responses arrive as pre-parsed JSON with human-readable field names and native types.
The migration is three lines of code. Change your endpoint from your current provider to grpc.subglow.io, add your Subglow API key to the metadata, and your existing subscription request works as-is. No Borsh decoding libraries, no instruction parser, no account mapping logic. The structured JSON output includes everything your bot needs — token amounts, buyer and seller addresses, bonding curve percentages, pool reserves, price impact — already extracted and labeled. You can delete hundreds of lines of deserialization code from your codebase and replace it with a single JSON.parse().
For the full output schema and available filters, see the documentation. For pricing details and tier comparison, check the plans page.
Yellowstone gRPC Tutorial
General Yellowstone gRPC setup across all languages.
Read tutorial →Python Alternative
Prefer Python? See the Python gRPC guide with grpcio.
Python guide →Pump.fun gRPC Streaming
Dedicated guide for streaming Pump.fun events via gRPC.
Pump.fun guide →Raydium gRPC Streaming
Stream Raydium AMM swaps and pool events in real time.
Raydium guide →Frequently asked questions
Which npm package should I use for Yellowstone gRPC?
@triton-one/yellowstone-grpc is the official client. Install with npm install @triton-one/yellowstone-grpc. It includes TypeScript type definitions out of the box.
How do I handle disconnects in TypeScript?
Wrap your subscription in a reconnection loop with exponential backoff. Track the last processed slot and resume from there. Listen for the 'error' and 'end' events on the stream to detect disconnections.
Can I subscribe to multiple programs simultaneously?
Yes. Add multiple program IDs to the account_include array in your transaction filter. All matching transactions stream through a single connection.
How does Subglow integrate with TypeScript?
Subglow works with the same @triton-one/yellowstone-grpc client. Change the endpoint to grpc.subglow.io and add your API key. Responses arrive as pre-parsed JSON instead of raw protobuf.
TypeScript + real-time Solana data.
Same Yellowstone client. Pre-parsed JSON output. Zero Borsh decoding. npm install and go.