-
Originally asked on stack overflow. On Aptos, the primary way to send a Token is in two phases, an offer by the sender and then an accept by the recipient. However, if users opt in to allowing direct transfer, the sender can just send that recipient an NFT in a single transaction. How do I check if a user has opted in to direct transfer? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You can tell if an account has opted-in to direct transfer by looking at the 0x3::token::TokenStore resource on their account. For example, using curl: curl https://fullnode.mainnet.aptoslabs.com/v1/accounts/0x232098630cfad4734812fa37dc18d9b8d59242feabe49259e26318d468a99584/resource/0x3::token::TokenStore This curl above means "get me the The output (run through 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"
}
}
}
}
} If direct_transfer is true, then they have opted-in to direct transfer. Using the TS SDK it would look like this: const client = new AptosClient(NODE_URL);
const resource = await client.getAccountResource(
accountAddress,
"0x3::token::TokenStore",
);
const hasOptedIn = (resource.data as any)["direct_transfer"] If you get a 404 when trying to retrieve the |
Beta Was this translation helpful? Give feedback.
-
Note, this is only applicable to token v1. With token v2 there is no notion of opting in to transfer, transfers to your account are always allowed. |
Beta Was this translation helpful? Give feedback.
You can tell if an account has opted-in to direct transfer by looking at the 0x3::token::TokenStore resource on their account. For example, using curl:
This curl above means "get me the
0x3::token::TokenStore
resource on account0x232098630cfad4734812fa37dc18d9b8d59242feabe49259e26318d468a99584
.The output (run through jq):