listCoins method

Future<Page<CoinData>> listCoins(
  1. String owner, {
  2. String coinType = '0x2::sui::SUI',
  3. String? cursor,
  4. int? limit,
})

Implementation

Future<Page<CoinData>> listCoins(
  String owner, {
  String coinType = '0x2::sui::SUI',
  String? cursor,
  int? limit,
}) async {
  final normalizedCoinType = normalizeStructTagString(coinType);
  final objectType = '0x2::coin::Coin<$normalizedCoinType>';

  final response = await _client.stateService.listOwnedObjects(
    ListOwnedObjectsRequest(
      owner: owner,
      objectType: objectType,
      pageSize: limit,
      pageToken: cursor != null ? base64Decode(cursor) : null,
      readMask: FieldMask(
        paths: ['object_id', 'version', 'digest', 'object_type', 'owner', 'balance'],
      ),
    ),
  );

  final hasNext = response.hasNextPageToken() && response.nextPageToken.isNotEmpty;
  return Page(
    data: response.objects.map((obj) {
      return CoinData(
        objectId: obj.objectId,
        version: obj.version.toString(),
        digest: obj.digest,
        owner: obj.hasOwner() ? _mapOwner(obj.owner) : const UnknownOwner(),
        type: normalizedCoinType,
        balance: obj.balance.toString(),
      );
    }).toList(),
    hasNextPage: hasNext,
    nextCursor: hasNext ? base64Encode(response.nextPageToken) : null,
  );
}