getAccountCollectionsWithOwnedTokens

abstract suspend fun getAccountCollectionsWithOwnedTokens(accountAddress: AccountAddressInput, tokenStandard: TokenStandard? = null, sortOrder: List<CollectionOwnershipV2ViewSortOrder>? = null, page: PaginationArgs? = null, minimumLedgerVersion: Long? = null): Result<GetAccountCollectionsWithOwnedTokensQuery.Data?, AptosIndexerError>

Queries for all collections that an account currently has tokens for.

This includes NFTs, fungible tokens, and soulbound tokens. This function first ensures the indexer is synchronized up to the specified minimumLedgerVersion before querying to guarantee up-to-date data.

Usage

val address = AccountAddress.fromString("0x...")
val resolution = aptos.getAccountCollectionsWithOwnedTokens(
accountAddress = address,
tokenStandard = TokenStandard.V2
)

when (resolution) {
is Result.Ok -> {
val collectionsData = resolution.value
println("Successfully retrieved collections data: $collectionsData")
}
is Result.Err -> println("Error retrieving collections: ${resolution.error.message}")
}

Return

A Result which is either Result.Ok containing the query data, or Result.Err containing an AptosIndexerError.

Parameters

accountAddress

The address of the account to query.

tokenStandard

An optional token standard to filter the results by (e.g., NFT).

sortOrder

An optional list of sorting options for the results.

page

Optional pagination arguments (limit and offset).

minimumLedgerVersion

An optional ledger version. The function will wait for the indexer to be at or beyond this version before querying.