Skip to content

How do you "await" and unsubscribe an Event Emitter checking pending transactions? #2176

Answered by zemse
proficy asked this question in Q&A
Discussion options

You must be logged in to vote

Does this work for you?

var scanTxPool = async () => {
    var myWallet = '0x0000000000000000000000000000000000000000';

    // this waits until resolve() is called
    await new Promise((resolve) => {
      provider.on("pending", async (txHash) => {
            provider.getTransaction(txHash).then(async (tx) => {
                if (tx && tx.to) {
                    if (tx.from === myWallet) {
                        console.log('Found my wallet!');
                        provider.removeAllListeners();
                        resolve();
                    }
                }
            });
      });
    })
    // do other stuff 
}

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@proficy
Comment options

@proficy
Comment options

@proficy
Comment options

@proficy
Comment options

@hakanyakar
Comment options

Answer selected by proficy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants