I am using Geyser endpoint provided by instantnodes and I have got premium service.
I am trying to subscribe to tx and following the docs of helius for yellowstone geyser usage.
async function main() {
// Open connection.
const client = new Client(GRPC_URL, X_TOKEN, {
"grpc.max_receive_message_length": 1024 * 1024 * 1024, // 64MiB
});
// Subscribe for events
const stream = await client.subscribe();
// Create `error` / `end` handler
const streamClosed = new Promise<void>((resolve, reject) => {
stream.on("error", (error) => {
reject(error);
stream.end();
});
stream.on("end", () => {
resolve();
});
stream.on("close", () => {
resolve();
});
});
// Handle updates
stream.on("data", (data) => {
let ts = new Date();
if (data) {
if(data.transaction) {
const tx = data.transaction;
// Convert the entire transaction object
const convertedTx = convertBuffers(tx);
// If you want to see the entire converted transaction:
console.log(`${ts.toUTCString()}: Received update: ${JSON.stringify(convertedTx)}`);
}
else {
console.log(`${ts.toUTCString()}: Received update: ${data}`);
}
stream.end();
} else if (data.pong) {
console.log(`${ts.toUTCString()}: Processed ping response!`);
}
});
// Example subscribe request.
const request: SubscribeRequest = {
commitment: CommitmentLevel.PROCESSED,
accountsDataSlice: [],
ping: undefined,
transactions: {
client: {
vote: false,
failed: false,
accountInclude: [
"675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"
],
accountExclude: [],
accountRequired: [],
},
},
// unused arguments
accounts: {},
slots: {},
transactionsStatus: {},
entry: {},
blocks: {},
blocksMeta: {},
};
// Send subscribe request
await new Promise<void>((resolve, reject) => {
stream.write(request, (err: any) => {
if (err === null || err === undefined) {
resolve();
} else {
reject(err);
}
});
}).catch((reason) => {
console.error(reason);
throw reason;
});
// Send pings every 5s to keep the connection open
const pingRequest: SubscribeRequest = {
// Required, but unused arguments
accounts: {},
accountsDataSlice: [],
transactions: {},
blocks: {},
blocksMeta: {},
slots: {},
transactionsStatus: {},
entry: {},
};
setInterval(async () => {
await new Promise<void>((resolve, reject) => {
stream.write(pingRequest, (err: null | undefined) => {
if (err === null || err === undefined) {
resolve();
} else {
reject(err);
}
});
}).catch((reason) => {
console.error(reason);
throw reason;
});
}, PING_INTERVAL_MS);
await streamClosed;
}
main();
You could check it as /data-streaming/geyser-yellowstone
When I run he code with endpoint providing req things in everything in correct format i get this in output:
Tue, 04 Feb 2025 07:45:14 GMT: Received update: [object Object]
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
at _write (node:internal/streams/writable:489:11)
at Writable.write (node:internal/streams/writable:510:10)
at C:\Users\aliha\Desktop\cp_tradingbot\dist\test.js:194:24
at new Promise (<anonymous>)
at C:\Users\aliha\Desktop\cp_tradingbot\dist\test.js:193:19
at Generator.next (<anonymous>)
at C:\Users\aliha\Desktop\cp_tradingbot\dist\test.js:41:71
at new Promise (<anonymous>)
at __awaiter (C:\Users\aliha\Desktop\cp_tradingbot\dist\test.js:37:12)
at Timeout._onTimeout (C:\Users\aliha\Desktop\cp_tradingbot\dist\test.js:192:27) {
code: 'ERR_STREAM_WRITE_AFTER_END'
}
node:internal/process/promises:394
triggerUncaughtException(err, true /* fromPromise */);
^
What I expect is that I could correctly subscribe to geyser endpoint and after that I could write request in it to get updates about specific data like subscribing to transactions.