getBlockByHeight

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

Retrieves block information by a specific block height.

Usage

val aptos = Aptos(AptosConfig(AptosSettings(network = Network.LOCAL)))
val resolution = aptos.getBlockByHeight(1L)

when (resolution) {
is Result.Ok -> {
val block = resolution.value
println("Ledger version for block is: ${block.lastVersion}")
}
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

ledgerHeight

The block height to look up, starting at 0.

withTransactions

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