Description
Problem
When working with transactions in a blockchain context, there is often a need to wait for a transaction to be confirmed by the network before proceeding with further actions. Currently, stacks lacks a straightforward way to wait for a transaction to be mined and achieve a specified number of confirmations.
Solution
I propose adding a waitForTransaction(txHash, confirmations)
function to the codebase. This function would operate similarly to ethers.js' waitForTransaction
method, allowing us to wait for a transaction identified by txHash
to be confirmed by the network a specified number of times (confirmations
). The function should:
- Accept a
txHash
(transaction hash) as input. - Optionally accept a
confirmations
parameter, defaulting to 1 if not provided. - Poll the blockchain at regular intervals to check the transaction status.
- Resolve once the transaction has been confirmed the specified number of times.
- Reject if the transaction fails or is not confirmed within a reasonable timeframe.
This utility would simplify the handling of transaction confirmations and reduce the likelihood of errors in the transaction flow.
Additional context
For reference, ethers.js provides a similar utility method: provider.waitForTransaction(txHash, confirmations)
. Implementing a similar function would streamline the development process, especially in scenarios where multiple confirmations are required before proceeding with further logic.
Metadata
Metadata
Assignees
Type
Projects
Status