getBlockByVersion

abstract suspend fun getBlockByVersion(ledgerVersion: Long, withTransactions: Boolean? = null): Result<Block, AptosSdkError>

Retrieves block information by a specific ledger version.

Usage

val aptos = Aptos(AptosConfig(AptosSettings(network = Network.LOCAL)))
val resolution = aptos.getBlockByVersion(2L)

when (resolution) {
is Result.Ok -> {
val block = resolution.value
println("Block height is: ${block.blockHeight}")
}
is Result.Err -> {
println("Error retrieving block: ${resolution.error.message}")
}
}

Return

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

Parameters

ledgerVersion

The ledger version to look up block information for.

withTransactions

If set to true, includes all transactions in the block.