Add `send_transaction_polling` to the SDK
When writing JS code, I need to poll transaction status manually, and it would be nice to have a helper method in the SDK for that, similar to rs rpc client's send_transaction_polling method
@janewang when OD Hack start, I would love to work on this issue I have a good track record as an onlydust contributor
Hi @Jemiiah! Maintainers during the ODHack # 8.0 will be tracking applications via OnlyDust. Therefore, in order for you to have a chance at being assigned to this issue, please apply directly here, or else your application may not be considered.
I am applying to this issue via OnlyDust platform.
My background and how it can be leveraged
Hi. My name is joy and i am a web3 developer and contributor.
How I plan on tackling this issue
I plan to solve this issue by creating a polling function that can send transactions and can also check the status of the transaction periodically. I will also add the helper method to the SDK.
I am applying to this issue via OnlyDust platform.
My background and how it can be leveraged
I'm Poulav Bhowmick, a software engineer at Invisible Studios with a robust background in TypeScript, Rust, Solidity Cairo, fullstack development and blockchain technology. My experience includes building robust applications, optimizing functionalities and blockchain integration. I have actively participated in events and open source contributions, enhancing my capability to tackle real-world tech challenges. My projects can be viewed on my GitHub Profile and OnlyDust Profile. Plus I´m active member of Starknet, Ethereum ecosystem.
How I plan on tackling this issue
I will implement the send_transaction_polling method in the JavaScript SDK as follows:
-
Add a new method to the appropriate class (likely the
RpcClientor similar):async sendTransactionPolling(tx, options = {}) { const hash = await this.sendTransaction(tx); return this.getTransactionPolling(hash, options); } -
Implement the getTransactionPolling method if it doesn't already exist:
async getTransactionPolling(hash, options = {}) {
const {
maxAttempts = 50,
interval = 1000,
timeoutMs = 60000,
} = options;
const startTime = Date.now();
for (let attempt = 0; attempt < maxAttempts; attempt++) {
try {
const response = await this.getTransaction(hash);
if (response.status !== 'pending') {
return response;
}
} catch (error) {
if (error.code !== 'transaction_not_found') {
throw error;
}
}
if (Date.now() - startTime > timeoutMs) {
throw new Error('Polling timeout exceeded');
}
await new Promise(resolve => setTimeout(resolve, interval));
}
throw new Error('Max polling attempts reached');
}
Update the SDK documentation to include these new methods, their parameters, return values, and possible errors. Add examples in the SDK README or documentation showing how to use the new sendTransactionPolling method. Ensure the new methods follow the SDK's existing coding style and conventions. Consider adding a way to cancel the polling operation if needed (e.g., using AbortController).
ETA - 4 days
I am applying to this issue via OnlyDust platform.
My background and how it can be leveraged
I have extensive experience in JavaScript and TypeScript, particularly in building SDKs and libraries for blockchain applications. My background in transaction handling and polling mechanisms will enable me to effectively implement the send_transaction_polling method to enhance user experience and simplify transaction status management.
How I plan on tackling this issue
I would start by reviewing the existing SDK code to understand the transaction flow. Then, I’d implement the send_transaction_polling method, ensuring it provides a straightforward interface for users. I would also incorporate error handling and customizable polling intervals, along with thorough testing to ensure reliability.
I am applying to this issue via OnlyDust platform.
My background and how it can be leveraged
I am a full-stack developer with experience in QA testing and languages like Python, Cairo, Solidity, React, and JavaScript.
How I plan on tackling this issue
i will Define Requirements Determine the polling interval and timeout. Identify the transaction status endpoints (e.g., /transaction/{id}/status). Decide on the polling strategy (e.g., interval-based, exponential backoff). Design the API Create a new method in the SDK send_transaction_polling(transaction_id, polling_interval, timeout) . Define the method's parameters and return types.
I am applying to this issue via OnlyDust platform.
My background and how it can be leveraged
Hello @janewang I commented previously before the ODHack started that I would love to work on this issue I'm a frontend developer with over 50 contributions to onlydust here's my onlydust profile : https://app.onlydust.com/u/Jemiiah
How I plan on tackling this issue
I will implement the send_transaction_polling method in the JavaScript SDK as follows:
Add a new method to the appropriate class (likely the RpcClient or similar):
const hash = await this.sendTransaction(tx);
return this.getTransactionPolling(hash, options);
}
Implement the getTransactionPolling method if it doesn't already exist:
async getTransactionPolling(hash, options = {}) {
const {
maxAttempts = 50,
interval = 1000,
timeoutMs = 60000,
} = options;
const startTime = Date.now();
for (let attempt = 0; attempt < maxAttempts; attempt++) {
try {
const response = await this.getTransaction(hash);
if (response.status !== 'pending') {
return response;
}
} catch (error) {
if (error.code !== 'transaction_not_found') {
throw error;
}
}
if (Date.now() - startTime > timeoutMs) {
throw new Error('Polling timeout exceeded');
}
await new Promise(resolve => setTimeout(resolve, interval));
}
throw new Error('Max polling attempts reached');
}
Update the SDK documentation to include these new methods, their parameters, return values, and possible errors. Add examples in the SDK README or documentation showing how to use the new sendTransactionPolling method. Ensure the new methods follow the SDK's existing coding style and conventions. Consider adding a way to cancel the polling operation if needed (e.g., using AbortController).
I am applying to this issue via OnlyDust platform.
My background and how it can be leveraged
With a foundation in JavaScript and have experience working with SDKs and APIs. My background in software development equips me with the skills to implement effective polling mechanisms, ensuring seamless transaction management in applications.
How I plan on tackling this issue
To enhance the SDK, I propose implementing a helper method for polling transaction status in JavaScript. This method should function similarly to the send_transaction_polling method found in the Rust RPC client. By adding this feature, I can streamline the process of monitoring transaction statuses, improving overall efficiency in handling transactions.
This is done in https://github.com/stellar/js-stellar-sdk/pull/1092