Our web app charges users X amount of SPL token. Users sign through their connected wallet. After the tx charges them, a request is sent to the back end where our server changes some metadata on their nft.
Goal: I would like to confirm that the tx executed correctly on the server. The reason is to prevent users from sending bogus requests to our backend and bypassing the front end SPL token tx.
Problem: The following code does not work. It never finds the tx. Oh, I also don't know what maxSupportedTransactionVersion should be set to lol
const tx = await connection.getTransaction(txSig, {
maxSupportedTransactionVersion: 100000000000000,
});
if (!tx) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Invalid TX",
// optional: pass the original error to retain stack trace
});
}
Is there a better way to do this?
Follow Up
It was suggested that we use connection.confirmTransaction()
. The code above was failing because getTransaction
defaults to only giving you transactions at finalized commitment
(eg. they have achieved the maximum number of confirmations).
Not sure how to use connection.confirmTransaction()
on our server. There is no parameter to specify the tx we are confirming!
Thank you for your help!