get Aptos Full Node
A high-level generic function to execute a GET request against an Aptos FullNode.
This function handles the entire lifecycle of a read request: it builds and executes the request, checks the HTTP response status, and deserializes the JSON body into the specified type T. It is designed to be completely type-safe and will not throw exceptions for predictable API or network errors.
Usage
// Define the data class that matches the expected JSON response
@Serializable
data class AccountData(val sequence_number: String, val authentication_key: String)
suspend fun fetchAccountData() {
// Setup request options
val address = AccountAddress.fromString("0x...")
val options = RequestOptions.GetAptosRequestOptions(
aptosConfig = aptos.config,
path = "accounts/${address}",
params = null
)
// Make the call, specifying the target type
val result: Result<AccountData, AptosError> = aptos.getAptosFullNode(options)
// Handle the result in a type-safe way
when (result) {
is Ok -> println("Sequence Number: ${result.value.sequence_number}")
is Err -> println("Error fetching account: ${result.error.message}")
}
}Return
A Result object:
Ok<T>: On success, contains the deserialized data of typeT.Err<AptosError>: On failure, contains a detailed error. This can be due to:
Network Failure: Problems connecting to the node (from the underlying
getcall).HTTP Error: The API returned a non-2xx status code (e.g., 404 Not Found, 500 Internal Server Error).
Deserialization Error: The response body could not be parsed into the target type
T.
Parameters
The data class type into which the successful JSON response body should be deserialized. Must be annotated with @Serializable.
The configuration for the request, including the path and any query parameters.