【问题标题】:How do I check if a user has opted in to direct transfer?如何检查用户是否已选择直接传输?
【发布时间】:2022-11-21 00:02:02
【问题描述】:

在 Aptos 中,发送 Token 的主要方式分为两个阶段,即发送者的报价和接收者的接受。但是,如果用户选择允许直接转账,发送方只需在单笔交易中向接收方发送 NFT。如何检查用户是否已选择直接传输?

【问题讨论】:

    标签: move-lang aptos


    【解决方案1】:

    您可以通过查看帐户上的 0x3::token::TokenStore 资源来判断帐户是否已选择直接转账。例如,使用卷曲:

    curl https://fullnode.mainnet.aptoslabs.com/v1/accounts/0x232098630cfad4734812fa37dc18d9b8d59242feabe49259e26318d468a99584/resource/0x3::token::TokenStore
    

    上面的 curl 意思是“给我 0x232098630cfad4734812fa37dc18d9b8d59242feabe49259e26318d468a99584 帐户上的 0x3::token::TokenStore 资源。

    输出(通过jq运行):

    {
      "type": "0x3::token::TokenStore",
      "data": {
        "burn_events": {
          "counter": "0",
          "guid": {
            "id": {
              "addr": "0x232098630cfad4734812fa37dc18d9b8d59242feabe49259e26318d468a99584",
              "creation_num": "6"
            }
          }
        },
        "deposit_events": {
          "counter": "6",
          "guid": {
            "id": {
              "addr": "0x232098630cfad4734812fa37dc18d9b8d59242feabe49259e26318d468a99584",
              "creation_num": "4"
            }
          }
        },
        "direct_transfer": true,
        "mutate_token_property_events": {
          "counter": "1",
          "guid": {
            "id": {
              "addr": "0x232098630cfad4734812fa37dc18d9b8d59242feabe49259e26318d468a99584",
              "creation_num": "7"
            }
          }
        },
        "tokens": {
          "handle": "0x91744f237fa81aedf45199a8c2bd568e7e329e48e02ae82786632fd0ebd3ad01"
        },
        "withdraw_events": {
          "counter": "0",
          "guid": {
            "id": {
              "addr": "0x232098630cfad4734812fa37dc18d9b8d59242feabe49259e26318d468a99584",
              "creation_num": "5"
            }
          }
        }
      }
    }
    

    如果direct_transfer 为真,则他们已选择直接转移。

    使用 TS SDK 它看起来像这样:

    const client = new AptosClient(NODE_URL);
    
    const resource = await client.getAccountResource(
        accountAddress,
        "0x3::token::TokenStore",
    );
    
    const hasOptedIn = (resource.data as any)["direct_transfer"]
    

    如果您在尝试检索 0x3::token::TokenStore 时收到 404,这也意味着他们没有选择直接转账,因为他们从未与令牌进行过交互。

    【讨论】:

      猜你喜欢
      • 2014-08-21
      • 1970-01-01
      • 2018-04-01
      • 2010-10-13
      • 2015-08-04
      • 2016-02-15
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多