Skip to content

Add a waitForTransactionFunction #1738

Open
@0x2me

Description

@0x2me

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:

  1. Accept a txHash (transaction hash) as input.
  2. Optionally accept a confirmations parameter, defaulting to 1 if not provided.
  3. Poll the blockchain at regular intervals to check the transaction status.
  4. Resolve once the transaction has been confirmed the specified number of times.
  5. 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

No one assigned

    Labels

    featureBrand new functionality. New pages, workflows, endpoints, etc.

    Type

    No type

    Projects

    Status

    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions