I'm struggling to implement the functionality which sends multiple transactions using the same address. here the from address is same but the to addresses are different. When I did research on this, I found that there are two ways to implement the approach -

  • Perform all transactions parallelly by incrementing the nonce one after one. Call getTransactionCount method one time and increment its count on all the subsequent transactions.

  • Implement the queue, In which the second transaction does not proceed until the first transaction mined.

When I analyzed the above two approach, I got to know about some issues -

  • In Approach 1, There may be possible that If one transaction will fail, So all the transaction after that nonce would become fail. But how does the metamask manage such type of cases? because the metamask also do the same thing and we can able to perform transactions one after one.

  • In Approach 2, In the queue process, one transaction depends on the prior transaction and it not initiated until first gets completed.

As I dig more into the approach, I found that the best approach would be the second one. (queue process)

But I stuck on the following cases while implementing the 2nd approach -

  • Because we don't know the exact time of the transaction mined in the block, how to decide the time interval to check whether the transaction block is mined or not. (I know that we use the ropsten.etherscan to check the transaction status)

  • If we give time Interval 15 sec. then it might be possible that transaction not mined in 1 hour and it keeps busy the server to send the request.

  • There might be such case, where one transaction could not mine until 2-3 days, due to some reasons. In this case what we need to do for overwriting that transaction. What will be the best approach to handle this?

Concerning second approach:

  • Choice of the time interval depends on the reaction time you want to have.
  • According to etherscan API documentation maximum rate is 5 requests per second: a time interval of 15 seconds is perfectly reasonable.
  • Overwriting a transaction is done simply by creating a transaction with the same nonce. Giving it a higher gas price incentivizes miners to mine it instead of the old one.

However you did not provide reasons of your preference for approach 2: I see no clear advantage of one approach over the other.

In case of approach 1: if a transaction fails (for example because not enough gas was provided), this transaction would be mined in a block and next transactions would execute normally. You seem to mix up failed and pending transactions.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.