1import Client, {
2 CommitmentLevel,
3 SubscribeRequest,
4} from "@triton-one/yellowstone-grpc";
5
6const client = new Client(
7 "https://geyser.therpc.io:443",
8 "<YOUR_API_KEY>",
9 undefined
10);
11
12const request: SubscribeRequest = {
13 accounts: {
14 raydium_pools: {
15 account: [],
16 owner: ["675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"],
17 filters: [],
18 nonemptyTxnSignature: undefined,
19 },
20 },
21 slots: {},
22 transactions: {},
23 transactionsStatus: {},
24 blocks: {},
25 blocksMeta: {},
26 entry: {},
27 accountsDataSlice: [],
28 commitment: CommitmentLevel.PROCESSED,
29};
30
31const stream = await client.subscribe();
32await new Promise<void>((resolve, reject) => {
33 stream.write(request, (err: Error | null) => {
34 if (err) reject(err);
35 else resolve();
36 });
37});
38
39stream.on("data", (update) => {
40 if (update.account) {
41 const acc = update.account.account;
42 console.log(
43 "slot:", update.account.slot,
44 "pubkey:", Buffer.from(acc.pubkey).toString("base64"),
45 "lamports:", acc.lamports,
46 "data_len:", acc.data.length
47 );
48 }
49});
50
51stream.on("error", (err) => console.error("stream error:", err));
52stream.on("end", () => console.log("stream ended"));