view
inline suspend fun <T : List<MoveValue>> General.view(payload: InputViewFunctionData, bcs: Boolean = true, ledgerVersion: LedgerVersionArg? = null): Result<T, AptosSdkError>
Queries a Move view function on the Aptos blockchain.
View functions are read-only and do not require gas or a transaction signature.
Usage
val aptos = Aptos(AptosConfig(AptosSettings(network = Network.LOCAL)))
val payload = InputViewFunctionData(
function = "0x1::chain_id::get",
typeArguments = emptyList(),
functionArguments = emptyList(),
)
val resolution = aptos.view<List<MoveValue.MoveUint64Type>>(payload)
when (resolution) {
is Result.Ok -> {
val data = resolution.value
println("View function returned: $data")
}
is Result.Err -> {
println("Error calling view function: ${resolution.error.message}")
}
}Content copied to clipboard
Return
A Result which is either Result.Ok containing an array of MoveValues, or Result.Err containing an AptosSdkError.
Parameters
payload
The description of the view function to call.
bcs
If true, uses BCS for the request payload. Defaults to true.
ledger Version
An optional ledger version to query.