I have a function that allows users to approve a smart contract to spend an amount of token on their behalf. The problem that I faced is when I trigger the function pay 2 transactions pop up, approve and transfer(normal). For a better user experience, I would like to wait until the first transaction gets mined and then call the second transaction.
Ps: I'm using web3.js
I tried to use :
.on('transitionsHash', hash => {})
But it didn't work.
Thank you
async function pay() {
setActivePayment(true);
const contractAddress = "0xc6988e2EfB0a11a529666b2cG43322Ce8A4C85a6";
token.methods
.approve(contractAddress, amount)
.send({from : account,
maxPriorityFeePerGas: null,
maxFeePerGas: null})
.then(
await token.methods
.transfer(contractAddress, amount)
.send({from : account,
maxPriorityFeePerGas: null,
maxFeePerGas: null
})
.once("error", (err)=> {
console.log(err);
setActivePayment(false);
showAlert(true, "Something went wrong...!");
})
.then((receipt)=> {
setActivePayment(false);
}))
}