get Account Info
Retrieves the Aptos blockchain for an account's on-chain state.
This function retrieves core information about a specific account, such as its sequence number and authentication key. The sequence number is crucial for transaction ordering and preventing replay attacks.
Optionally, you can query the account's state at a specific historical ledger version, providing a snapshot of the account at that point in time.
Usage
The function returns a Result object that must be handled. Using a when expression is the safest way to process the outcome.
val address = AccountAddress.fromString("0x...")
val accountInfoResult = aptos.getAccountInfo(address)
// Example 1: Robust handling with a 'when' expression
when (accountInfoResult) {
is Result.Ok -> {
println("Success! Sequence Number: ${accountInfoResult.value.sequenceNumber}")
}
is Result.Err -> {
println("Error fetching account: ${accountInfoResult.error}")
}
}
// Example 2: Safely getting the value or null
val accountData = accountInfoResult.getOrNull()
if (accountData != null) {
println("Account exists with sequence number: ${accountData.sequenceNumber}")
} else {
println("Could not retrieve account data.")
}Return
A Result object which will be either Result.Ok<AccountData> on success or Result.Err<AptosError> on failure.
Result.Ok: Contains theAccountData, including thesequenceNumberandauthenticationKey.Result.Err: Encapsulates anAptosErrordetailing what went wrong (e.g., account not found, network issue).
Parameters
The 32-byte address of the Aptos account to query. This can be provided in various formats via the AccountAddressInput type.
A lambda function to configure optional query parameters, such as specifying a ledgerVersion to query the state from the past.