get Block By Height
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}")
}
}Content copied to clipboard
Return
A Result which is either Result.Ok containing the Block information, or Result.Err containing an AptosSdkError.
Parameters
ledger Height
The block height to look up, starting at 0.
with Transactions
If set to true, includes all transactions in the block.