Say I need a user to approve a contract with an erc20 token balance and then the contract can execute it's function after. Typically, I would have to do an approve
transaction with a nonce of 1 and then call the contract after that with a nonce of 2.
This means that we have to wait at least two blocks before the total of the two transactions complete.
How can I send these transactions at the same time, and included in the same block while still ensuring the ordering of their execution?
It might look something like this:
await sendTransactions([
token.approve(myContract, toWei('1000000')), // Gets executed in the same block before someFunction
myContract.someFunction() // Gets executed in the same block after approve function
]);
This means that we have to wait at least two blocks before the total of the two transactions complete
- you're assuming that each transaction gets executed in a new block, which is wrong.sendTransactions
, just addawait
at the beginning of each line.