Solana's lightning-fast blockchain demands real-time data solutions. Enter gRPC streaming with Solana Tracker - a powerful way to tap into the pulse of Solana transactions as they happen. This guide will walk you through setting up a gRPC stream for live Solana transaction data.
Why gRPC Streaming?
- Real-Time Updates: Get transaction data the instant it hits the blockchain.
- Efficient Filtering: Receive only the data relevant to your application.
- High Performance: gRPC's lightweight protocol ensures speedy data transfer.
Prerequisites
Before we dive in, make sure you have:
- A Solana Tracker shared gRPC or a dedicated node Available here
- A server-side backend (we'll use Node.js in this example)
Setting Up the Stream
1. Initialize the gRPC Client
First, install the Yellowstone gRPC client from Triton:
npm install @triton-one/yellowstone-grpc
Then, set up your client:
import Client from "@triton-one/yellowstone-grpc";
const client = new Client(
"https://grpc.solanatracker.io", // Your Solana Tracker gRPC URL
"key-here",
undefined
);
2. Subscribe to Transactions
Create a subscription request to filter the transaction stream:
const req = {
accounts: {},
slots: {},
transactions: {
pump: {
vote: false,
failed: false,
signature: undefined,
accountInclude: ['6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P'], // Pumpfun Address
accountExclude: [],
accountRequired: [],
},
},
transactionsStatus: {},
entry: {},
blocks: {},
blocksMeta: {},
accountsDataSlice: [],
ping: undefined,
commitment: CommitmentLevel.CONFIRMED, // Receive Confirmed Transactions
};
const stream = await client.subscribe();
3. Process the Stream
Handle incoming transaction data:
stream.on("data", (data) => {
if (data?.transaction) {;
// Process transaction data here
}
});
Handling Disconnects
Implement a reconnection mechanism for reliability:
async function maintainSubscription(client, request) {
while (true) {
try {
await handleStream(client, request);
} catch (error) {
console.error("Stream error, reconnecting in 1s...", error);
await new Promise(resolve => setTimeout(resolve, 1000));
}
}
}
Conclusion
With Solana Trackers's Yellowstone gRPC service, you now have a powerful tool to stream and process Solana transactions in real-time. This opens up possibilities for building responsive DApps, trading bots, and analytics platforms that can react instantly to on-chain events.
Ready to start? Get your Dedicated Node or Shared gRPC server from solanatracker.io and start streaming real-time Solana data!
Resources
Happy coding!