2

On Solana, what would be the most reliable way to get 100% certainty that a trade done with web3.js was successful?

More specifically i use the raydium sdk function:

const { innerTransactions } = await Liquidity.makeSwapInstructionSimple(...);

A quick way, might be to simply check the wallet balance, but that might be faulty due to possible rollbacks. I have tried checking for await connection.getSignatureStatus(txId)

and then:

if (status && ((status.confirmationStatus === 'confirmed' || status.confirmationStatus === 'finalized')))

However there was also a transaction that was confirmed and finalized, but still failed and was not recognized as such. Trying it with web3.sendAndConfirmTransaction for some reason results in "ws error: Unexpected server response: 404" log errors.

So i would be very interested in understanding what others do in their programs?

2

1 Answer 1

0

In my opinion the best way to go is to fetch the transaction from connection rpc, see this : https://www.quicknode.com/docs/solana/getParsedTransaction

Then, if you get something, it menas the transaction was accepted by the blockchain.

Then, you check meta.err, if it's null it means the transaction succeeded. If there is an error, it means the transaction failed.

Checking account balance is not a great practice imo because of gas fees & possible failed transactions

3
  • Thank you and Ademola. This is something to try out. Since its a raydium lp pool buy, i get 4 instructions. So i assume i have to check all of their success, presumably also in the right order? Jan 17 at 15:22
  • no, if they are all in the same transaction, either the transaction succeed either it fails for ALL instruction. (make sure it's 4 instructions and not 4 transactions)
    – Effe2
    Jan 17 at 17:51
  • I still don't get it working reliably. I implemented as suggested: const response = await this.fetchSignatureStatuses(txids[0]); if (response && ((response.result.value.confirmationStatus === 'confirmed' || response.result.value.confirmationStatus === 'finalized' || this.onSignatureResponse == 1))) { Then i check: const confirmedTx = await connection.getTransaction(txId, getVersionedTransactionConfig) for confirmedTx.meta.err But this doesn't yield a result for 10 attempts = 10 seconds. Jan 20 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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