su8898
su8898

Reputation: 1713

Solana: Check if deposit is finalized?

How can we check if a deposit is finalized using solana/web3.js? I've tried using getTransaction with commitment parameter finalized and I did get a response with slot number. However, it took a few more seconds for Solana Explorer to show status Finalized. This probably means receiving slot number in a response to getTransaction doesn't necessarily mean a deposit is finalized?

Upvotes: 0

Views: 846

Answers (2)

Jon C
Jon C

Reputation: 8472

You can use Connection.confirmTransaction with the finalized commitment to check that a transaction has landed. For example:

const signature = await connection.sendTransaction(transaction, signers);
const status = await connection.confirmTransaction(
            {
              signature: signature,
              blockhash: transaction.recentBlockhash,
              lastValidBlockHeight: transaction.lastValidBlockHeight,
            },
          )
        ).value;
if (status.err) {
  throw new Error(
    `Transaction ${signature} failed (${JSON.stringify(status)})`,
  );
}

This was lifted from https://github.com/solana-labs/solana/blob/master/web3.js/src/util/send-and-confirm-transaction.ts

Upvotes: 0

mryalamanchi
mryalamanchi

Reputation: 1

Have you tried using 'confirmed' instead?

https://solana-labs.github.io/solana-web3.js/modules.html#Finality

Upvotes: 0

Related Questions