getTokenForAccount method
Queries token balance for a token account.
Implementation
Future<Token> getTokenForAccount(String account, TokenId tokenId) async {
final tokenStore = await aptosClient.getAccountResource(
account,
"0x3::token::TokenStore",
);
final handle = tokenStore["data"]["tokens"]["handle"];
final tableItem = TableItem("0x3::token::TokenId", "0x3::token::Token", tokenId);
try {
final resp = await aptosClient.queryTableItem(handle, tableItem);
return Token.fromJson(resp);
} catch (e) {
dynamic err = e;
if (err.response.statusCode == 404) {
return Token(tokenId, "0", PropertyMap());
}
rethrow;
}
}