【问题标题】:How to differentiate between a successful transaction and a failed transaction to display the transaction status in the UI?如何区分成功交易和失败交易以在 UI 中显示交易状态?
【发布时间】:2022-07-16 15:27:07
【问题描述】:

我试图在用户进行交易后根据 UI 中的 tx 哈希显示交易状态。

我注意到方法ft_resolve_transfer result 是 tx 成功时的值,而 tx 失败时为 0。

当我查看运行此命令后给出的响应 JSON 时

NEAR_ENV=mainnet  near tx-status DG4vGH3EagGQJsdRTSjWLHxZYrriHbki4imqFBeJzSc1 --accountId skiran017.near

JSON 与我在交易成功时得到的几乎相似。

我需要查看任何特定的键值对来找出成功和失败 tx 之间的区别吗?

发送失败:https://explorer.mainnet.near.org/transactions/DG4vGH3EagGQJsdRTSjWLHxZYrriHbki4imqFBeJzSc1

成功的交易: https://explorer.mainnet.near.org/transactions/8WRJ39F1UGB5fXcLBUS5tz5mmmis4czL9U8S1SoddiNj

    标签: nearprotocol


    【解决方案1】:

    目前我通过利用status: { SuccessValue: 'IjAi' } 解决了这个问题。我们可以在使用 txHash 和 accountId 查询交易状态时返回的 JSON 对象中找到它。

    成功值键具有 base64 中的值。我将其解码为 ASCI 并检查它是否不为零。到目前为止,所有非零值都是成功的交易。

    function getTxStatus(txHash: string, accountId: string) {
        if (!txHash || !accountId) {
          return;
        }
        checkTransactionStatus(txHash, accountId).then((res: any) => {
          const status: any = res.status;
          const data: string | undefined = status.SuccessValue;
    
          if (data) {
            const buff = Buffer.from(data, 'base64');
            const value = buff.toString('ascii');
    
            console.log(value); // check this for non zero value
          }
        });
      }
    

    感谢 Ref Finance 团队,参考了他们的代码。

    注意:当代币没有存储押金时,调用 ft_sotrage 来存储代币,此时 txHashes 是一个数组,其中 txHash on 0 index 表示存储相关的详细信息,第二个 txHash 在第一个包含 tx 详细信息的索引上.

    【讨论】:

      猜你喜欢
      • 2018-10-03
      • 1970-01-01
      • 2014-04-09
      • 2021-05-11
      • 2018-05-10
      • 1970-01-01
      • 1970-01-01
      • 2015-08-27
      • 2013-08-15
      相关资源
      最近更新 更多