Geyser · Code Examples

Geyser streaming examples

Drop-in examples for TypeScript, Rust and Python using the standard Yellowstone gRPC proto. Subscribe to Raydium pool accounts with an owner filter at CommitmentLevel.PROCESSED.
import Client, {
CommitmentLevel,
SubscribeRequest,
} from "@triton-one/yellowstone-grpc";
const client = new Client(
"https://geyser.therpc.io:443",
"<YOUR_API_KEY>",
undefined
);
const request: SubscribeRequest = {
accounts: {
raydium_pools: {
account: [],
owner: ["675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"],
filters: [],
nonemptyTxnSignature: undefined,
},
},
slots: {},
transactions: {},
transactionsStatus: {},
blocks: {},
blocksMeta: {},
entry: {},
accountsDataSlice: [],
commitment: CommitmentLevel.PROCESSED,
};
const stream = await client.subscribe();
await new Promise<void>((resolve, reject) => {
stream.write(request, (err: Error | null) => {
if (err) reject(err);
else resolve();
});
});
stream.on("data", (update) => {
if (update.account) {
const acc = update.account.account;
console.log(
"slot:", update.account.slot,
"pubkey:", Buffer.from(acc.pubkey).toString("base64"),
"lamports:", acc.lamports,
"data_len:", acc.data.length
);
}
});
stream.on("error", (err) => console.error("stream error:", err));
stream.on("end", () => console.log("stream ended"));

Replace <YOUR_API_KEY> with the key from your TheRPC dashboard. The x-token header is passed automatically by the Yellowstone client.