eth_sendTransaction eth_getTransactionByHash inconsistency

I make the following sequence of operations:

  • Call sendTransaction -> receive tx hash
  • Call getTransactionByHash - receive no transaction.
  • Call sendTransaction for the same transaction a second later, I get “nonce too low”
  • Call getTransactionByHash in a hope that nonce conflict received from the fact that tx was mined in that 1 second delay period -> receive no transaction
  • Call sendTransaction with same parameters but with increased gasPrice from different account (limitation of my system that I can not use the same one) -> receive new tx hash

In the end, both tx hashes get mined and I have no way to make sure my tx is mined only once.

Is there any way to make sure sendTransaction and getTransactionByHash are consistent?
Is there any way to implement sendOrGetTransaction to make sure I can consistent result if tx is already mined - do not send it again?

Hello @Bogdan_Gusiev, thanks for the details and question!

getTransactionByHash contains details about the block that the tx is mined in, and so it won’t return until after the tx is mined. The recommended way is to call getTransactionByHash repeatedly until it does return the tx. The ethereum block time is ~13 seconds, and so you’ll need to wait 10-20 seconds on average until the tx details are available.

Calling the same sendTransaction but from a different account will always have a different tx hash.