【问题标题】:solana candy machine - is it possible to know if user click approve in transactionsolana 糖果机 - 是否可以知道用户是否在交易中点击批准
【发布时间】:2021-12-28 07:58:13
【问题描述】:

我正在使用 solana 糖果机来铸造 nft。

当我在 javascript 中调用智能合约函数时

import * as anchor from "@project-serum/anchor";

let program = new anchor.Program(idl, programId, provider);
let result = await program.rpc.someFunc(); //here is the smart contract function

浏览器将显示弹出窗口供您批准交易。 有什么方法可以知道用户是点击取消还是批准?

在以太坊中,它有如下内容:

          .on("transactionHash", function(hash) {
                …
          })
          .on("error", function(error, receipt) {
        …
          });

可以用糖果机做吗?我想在用户点击交易中批准后做一些事情

【问题讨论】:

    标签: javascript wallet solana metaplex candy-machine


    【解决方案1】:

    是的,您可以实现类似的效果,但是直接从糖果机上不会有效。

    可能有多种方法可以做到这一点,但我发现一种方法是使用来自 Serum 的connection.getSignatureStatuses()

    代码看起来像这样,并且与您共享的内容相似:

    // Impor the connection dependencies
    import * as anchor from '@project-serum/anchor';
    
    // Loop using waiting for a positive status / or timeout
    while (...) {
    
      // Get the status using the transaction ID
      const statusResponse = await connection.getSignatureStatuses([
        txId,
      ]);
    
      const status = statusResponse?.value[0];
    
      if (status.err) {
        // ...
      }
    }
    

    一旦您获得交易的状态,包括用户拒绝它,您就可以在前端触发该行为。

    【讨论】:

      猜你喜欢
      • 2014-08-16
      • 1970-01-01
      • 2013-11-04
      • 2018-09-11
      • 1970-01-01
      • 2016-02-17
      • 2021-12-18
      • 2010-12-30
      • 2018-01-20
      相关资源
      最近更新 更多