getTableItem

inline suspend fun <T> Table.getTableItem(handle: String, data: TableItemRequest, param: LedgerVersionQueryParam? = null): Result<T, AptosSdkError>

Retrieves a specific item from a table, identified by the table's handle and the item's key.

Usage

// First, get a table handle and key from a known resource
val resourceResult = aptos.getAccountResource<SupplyWrapper>(...)
val (handle, key) = resourceResult.value.data.supply.vec.first().aggregator.vec.first()

// Then, retrieve the specific item from that table
val resolution = aptos.getTableItem<Long>(
handle = handle,
data = TableItemRequest(key_type = "address", value_type = "u128", key = key),
)

when (resolution) {
is Result.Ok -> {
val data = resolution.value
println("Successfully retrieved table item value: $data")
}
is Result.Err -> {
println("Error retrieving table item: ${resolution.error.message}")
}
}

Return

A Result which is either Result.Ok containing the deserialized table item of type T, or Result.Err containing an AptosSdkError.

Parameters

T

The data class to deserialize the table item's value into.

handle

A pointer to where the table is stored.

data

An object that describes the table item, including its key and value types.

param

An optional ledger version to query.