Transaction deduplication

Hello!
I use JSON RPC API for communication with Solana, but I have the next problem with sending transactions.
I send a transaction to Solana and “SendTransaction” method can return the next responses:

  1. ok (with transaction ID)
  2. error “AlreadyProcessed”
  3. error “BlockhashNotFound”

I’ll get all these response when sending multiple time the same transaction (of course if transaction is correct). But I can get error “BlockhashNotFound” even with the first sending. In this case I want just recreate a transaction with a new blockhash and send it again.

Also it is worth noting I want to stop sending a transaction after getting a transaction ID.

Thus if I’ve sent a correct transaction (with not old blockhash) and lost (by any reason) a transaction Id returned from Solana , later on resending if I get error “BlockhashNotFound” I won’t understand what happened - or my first sending was correct (and I just lost the transaction ID) or my first sending was failed and I should recreate a transaction and resend it again.

The question is how can I get the status or ID of a sent transaction by a serialized value of transaction or some other way?

Hi @satuban and welcome to the forum! :wave:

The transaction ID is the simply the base-58 encoded version of the first signature for the transaction.

Once you have a Transaction class and you’ve signed it, before you send it you can get the transaction ID by doing transaction.signature. That will return a Buffer, which I think ( I haven’t tested this specifically ) you can get a base-58 encoded string from by using the bs58 npm package and running bs58.encode(transaction.signature).

Hi @zicklag thanks a lot for your answer! It resolves my problem.

1 Like