You can also do it like this, by specifying number of block confirmations you'd like to wait for before proceeding. Note: You'll have to first instantiate account and target contract with web3. (https://web3js.readthedocs.io/en/v1.2.11/callbacks-promises-events.html):
const signedTxencoded = await accounttokenContract.signTransactionmethods.approve(txrouterAddr, amountToSend);.encodeABI()
console.log("Sendingconst transaction...");
tx = {
web3.eth.sendSignedTransaction(signedTx.rawTransaction) gas: 100000,
.once('transactionHash'to: tokenAddr,
function (hash) { data: encoded
}
const signedTx = await account.signTransaction(tx);
console.log("Transaction"Sending hash:transaction...", hash);
const targetConfirmations = })3;
await new .oncePromise('receipt'(resolve, function (receiptreject) => {
const promiEvent console= web3.logeth.sendSignedTransaction("Transaction receipt received:", receiptsignedTx.rawTransaction);
})promiEvent
.on('confirmation', function (confNumber, receipt) => {
console.log("Confirmation number:", confNumber);
if (confNumber ===>= 5targetConfirmations) { // Wait for
5 confirmations
console.log("Received`Received 5${targetConfirmations} confirmations. Transaction is confirmed."`);
promiEvent.off('confirmation'); // Remove all confirmation handlers
resolve(receipt); // Resolve the promise after the desired confirmations
}
})
.on('error', function (error) => {
console.error("Error:", error);
} reject(error)
; // Reject the promise if .then(functionthere's (receipt)an {error
console.log("Tx successful")
});
});