Soroban Rpc Response
@Serializable
Represents a JSON-RPC 2.0 response returned by the Soroban RPC server.
All Soroban RPC API responses follow the JSON-RPC 2.0 protocol. This class provides a type-safe wrapper for parsing responses and detecting errors.
JSON-RPC 2.0 Response Structure
A valid JSON-RPC 2.0 response contains:
jsonrpc: Protocol version (always "2.0")id: Identifier matching the request IDEither:
result: The successful result data (when no error occurred)error: Error information (when the request failed)
A response MUST contain either result or error, but never both.
Example Usage
val response: SorobanRpcResponse<GetHealthResponse> = parseResponse(json)
if (response.isSuccess()) {
val health = response.result!!
println("Server status: ${health.status}")
} else if (response.isError()) {
val error = response.error!!
println("Error ${error.code}: ${error.message}")
}Content copied to clipboard
Parameters
T
The type of the successful result data
See also
Constructors
Link copied to clipboard
constructor(jsonRpc: String, id: String, result: T? = null, error: SorobanRpcResponse.Error? = null)