web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

Unsubscribing from confirmation

Open lpeppe opened this issue 7 years ago • 2 comments

Hi everybody. I was wondering how to unsubscribe from the confirmation event returned by the send method. I need to wait for some blocks to be mined before considering my transaction accepted.

myContract.methods
        .transfer(to, amount)
        .send({ from: from })
        .on("confirmation", (confirmationNumber, receipt) => {
          console.log(confirmationNumber);
          // if(confirmationNumber > 12) unsubscribe() 
        });

lpeppe avatar Jul 12 '19 14:07 lpeppe

You are able to configure the number of blocks over the Web3ModuleOptions as described here.

nivida avatar Jul 12 '19 15:07 nivida

Maybe you can use off option on callback promises events https://web3js.readthedocs.io/en/v1.2.0/callbacks-promises-events.html#promievent

MaestosoToad avatar Jul 31 '19 23:07 MaestosoToad