getCoinType method
Implementation
Future<String?> getCoinType(String coinId) async {
final resp = await suiClient.getObject(
coinId,
options: SuiObjectDataOptions(showType: true),
);
final type = resp.data?.type;
if (type == null) {
return null;
}
final parsed = parseStructTag(type);
// Modification handle case like 0x2::coin::Coin<0xf398b9ecb31aed96c345538fb59ca5a1a2c247c5e60087411ead6c637129f1c4::fish::FISH>
if (parsed.address == NORMALIZED_SUI_COIN_TYPE.split('::')[0] &&
parsed.module == 'coin' &&
parsed.name == 'Coin' &&
parsed.typeParams.isNotEmpty
) {
final firstTypeParam = parsed.typeParams[0];
return firstTypeParam is StructTag
? '${firstTypeParam.address}::${firstTypeParam.module}::${firstTypeParam.name}'
: null;
} else {
return null;
}
}