getAccountTokensCount

open suspend override fun getAccountTokensCount(accountAddress: AccountAddressInput, page: PaginationArgs?, minimumLedgerVersion: Long?): Result<Long, AptosIndexerError>

Queries the total count of tokens owned by a specific account.

This function first ensures the indexer is synchronized up to the specified minimumLedgerVersion before querying to guarantee the count is up-to-date.

Usage

val address = AccountAddress.fromString("0x...")
val resolution = aptos.getAccountTokensCount(address)

when (resolution) {
is Result.Ok -> {
val count = resolution.value
println("Account owns $count tokens.")
}
is Result.Err -> println("Error retrieving tokens count: ${resolution.error.message}")
}

Return

A Result which is either Result.Ok containing the total token count as a Long, or Result.Err containing an AptosIndexerError.

Parameters

accountAddress

The address of the account to query.

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.