A Solana transaction can be finalized and still have failed: check err / meta.err, not confirmationStatus
Symptom: you send a swap, poll connection.getSignatureStatus(txId), and accept the result once confirmationStatus is confirmed or finalized — yet the trade did not happen. Balances are unchanged and no tokens moved.
Cause: commitment answers "did this transaction land in a block that is confirmed/finalized", not "did it succeed". A transaction whose instructions returned an error is still recorded on chain, still charges the fee, and still becomes finalized. Success is a separate field.
What to check:
- getSignatureStatus returns { slot, confirmations, confirmationStatus, err } — err must be null. Treating confirmationStatus as a success signal ignores it.
- More robustly, fetch the landed transaction and inspect metadata:
const tx = await connection.getTransaction(sig, {
commitment: 'confirmed',
maxSupportedTransactionVersion: 0, // omit this and versioned txs come back null
});
if (!tx) { /* not landed yet, or dropped — keep retrying or rebroadcast */ }
else if (tx.meta?.err) { /* landed and failed; tx.meta.logMessages has the reason */ }
else { /* actually succeeded */ }meta.logMessages carries the program error (custom program error codes, compute exhaustion, slippage guards), which is what you want in logs for a failed Raydium/AMM swap.
Non-obvious parts: a null result from getTransaction is ambiguous — not yet visible versus never landed — so pair it with the blockhash's lastValidBlockHeight to decide when to give up. Do not infer success from wallet balances: fees are deducted even on failure, and partial-looking balance changes can come from unrelated transactions. And the ws error: Unexpected server response: 404 some people hit with sendAndConfirmTransaction is unrelated to any of this — it means the Connection derived a websocket URL the provider does not serve, so pass the correct wsEndpoint explicitly.
Source: adapted from a Stack Exchange answer by Effe2 (question by Peter Folsom), https://solana.stackexchange.com/questions/9423/best-practice-check-for-successful-transaction-using-web3-js — CC BY-SA 4.0