Suppose I sign and send several transactions using the following function:
async function send(web3, account, transaction) {
const options = {
to : transaction._parent._address,
data: transaction.encodeABI(),
gas : await transaction.estimateGas({from: account.address})
};
const signed = await web3.eth.accounts.signTransaction(options, account.privateKey);
const receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction);
return receipt;
}
As you can see, I leave the nonce configuration to the node.
After signing and sending all transactions, I iterate the receipts in order to determine that all transactions have been added to the blockchain:
for (let i = 0; i < receipts.length; i++) {
while (receipts[i].blockNumber + 12 > await web3.eth.getBlockNumber()) {
web3.currentProvider.send({method: "evm_mine"}, () => {}); // if running on ganache
}
if (await web3.eth.getTransactionReceipt(receipts[i].transactionHash)) {
console.log(`transaction ${i} confirmed`);
}
else {
console.log(`transaction ${i} cancelled`);
}
}
It is crucial to me that the transactions will be added to the blockchain by order of submission.
I know that the nonce ensures this, but I am wondering, in case a transaction ends up in an orphaned/forked block, what happens to all remaining transactions, and how can I still ensure that they will be executed by order?
It would be very easy for me if I knew that all remaining transactions were subsequently removed from the pool, in which case, I could simply resubmit all of them without setting the nonce to any specific value.
Can I count on it, or should I take the "orphaned" transaction and resubmit it with the exact same nonce? And how should I handle the remaining transactions?
Thank you!