getTokenData method

Future<TokenData> getTokenData(
  1. String creator,
  2. String collectionName,
  3. String tokenName
)

Queries token data from collection.

Token data in below format

TokenData {
    String collection;
    String description;
    String name;
    int maximum;
    int supply;
    int uri;
    PropertyMap defaultProperties;
    List<bool> mutabilityConfig;
  }

Implementation

Future<TokenData> getTokenData(
  String creator,
  String collectionName,
  String tokenName,
) async {
  final collection = await aptosClient.getAccountResource(
    creator,
    "0x3::token::Collections",
  );
  final handle = collection["data"]["token_data"]["handle"];
  final tokenDataId = {
    "creator": creator,
    "collection": collectionName,
    "name": tokenName,
  };

  final tableItem = TableItem("0x3::token::TokenDataId", "0x3::token::TokenData", tokenDataId);

  final rawTokenData = await aptosClient.queryTableItem(handle, tableItem);
  return TokenData(
    rawTokenData["collection"] ?? collectionName,
    rawTokenData["description"],
    rawTokenData["name"],
    int.tryParse(rawTokenData["maximum"]),
    int.parse(rawTokenData["supply"]),
    rawTokenData["uri"],
    rawTokenData["default_properties"],
    rawTokenData["mutability_config"],
  );
}