【问题标题】:How to check whether transaction is successful and print the transaction signature in Solana Pay using Web3.js?如何使用 Web3.js 在 Solana Pay 中检查交易是否成功并打印交易签名?
【发布时间】:2022-09-22 21:41:08
【问题描述】:

我已经使用 Web3.js 集成了 Solana Pay。我也得到了交易签名。但我想检查交易是否成功。我正在使用 solana/web3.js v1.41.3。

下面是代码:

                const { signature } = await window.solana.signAndSendTransaction(transaction);
                await connection.confirmTransaction(signature);
                console.log(connection);
                
                
            

上面的代码运行良好,但我想检查交易是否成功。怎么做?

    标签: solana-web3js


    【解决方案1】:

    您可以使用 connection 对象的 getSignatureStatus,例如

    const getConfirmation = async (connection: Connection, tx: string) => {
      const result = await connection.getSignatureStatus(tx, {
        searchTransactionHistory: true,
      });
      return result.value?.confirmationStatus;
    };
    

    【讨论】:

      猜你喜欢
      • 2021-09-13
      • 2022-07-16
      • 2022-01-04
      • 1970-01-01
      • 2022-07-22
      • 1970-01-01
      • 2022-11-11
      • 1970-01-01
      • 2021-12-18
      相关资源
      最近更新 更多