I'm using third party SDK method and completing the transaction successfully. I'm trying to do the same function twice within a single ETH transaction. It's impossible with SDK method. I tried to deploy my own smart contract by using this function, but unfortunately, it doesn't have function's/smart contract's ABI. I have checked web3, ethers.js for any solution but could not find one.
const firstTx = await api.method(); // returns transactionHash
const secondTx = await api.method(); // returns transactionHash
Separately they work perfectly, but I need to process them with a single transaction. The second transaction depends on the first one, so it has to wait for the first function. Also, if any of the functions fail, both transactions should fail.
const singleTx = async() => {firstTX(); secondTx()} or {firstTx().then(()=>secondTx())} //returns single transactionHash
I need to implement it in a similar way. I'm stuck with that issue for more than 2 days. Any recommendation is greatly appreciated!
In web3js, there's a .send
function that returns a promise event. The event returns a few parameters, here you're looking for confirmation
.
You could do something along the lines of:
myContract.methods.firstTx(args).send({from: wallet})
.on('confirmation', function(confirmationNumber, receipt){
myContract.methods.secondTx(args)
})