getLedgerInfo

abstract suspend fun getLedgerInfo(): Result<LedgerInfo, AptosSdkError>

Retrieves the latest ledger information from a fullnode.

This includes details such as chain ID, epoch, and the current ledger version.

Usage

val aptos = Aptos(AptosConfig(AptosSettings(network = Network.LOCAL)))
val resolution = aptos.getLedgerInfo()

when (resolution) {
is Result.Ok -> {
val ledgerInfo = resolution.value
println("Current chain ID: ${ledgerInfo.chainId}")
}
is Result.Err -> {
println("Error retrieving ledger info: ${resolution.error.message}")
}
}

Return

A Result which is either Result.Ok containing the LedgerInfo, or Result.Err containing an AptosSdkError.