在Aptos上,发送令牌的主要方式分为两个阶段,发送方发出要约,然后接收方接受。但是,如果用户选择允许直接转账,则发送方可以在单笔交易中向该接收方发送NFT。如何检查用户是否已选择直接转帐?
您可以通过查看帐户上的0x3::token::TokenStore
资源来判断帐户是否已选择直接转账。例如,使用curl:
curl https://fullnode.mainnet.aptoslabs.com/v1/accounts/0x232098630cfad4734812fa37dc18d9b8d59242feabe49259e26318d468a99584/resource/0x3::token::TokenStore
上面的旋度意味着"给我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,这也意味着他们没有选择直接传输,因为他们从未与令牌交互。