web3.js
web3.js copied to clipboard
Unsubscribing from confirmation
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()
});
You are able to configure the number of blocks over the Web3ModuleOptions as described here.
Maybe you can use off option on callback promises events https://web3js.readthedocs.io/en/v1.2.0/callbacks-promises-events.html#promievent