SorobanRpcRequest

@Serializable
data class SorobanRpcRequest<T>(val jsonRpc: String = "2.0", val id: String, val method: String, val params: T? = null)

Represents a JSON-RPC 2.0 request sent to the Soroban RPC server.

All Soroban RPC API calls use the JSON-RPC 2.0 protocol over HTTP. This class provides a type-safe wrapper for constructing requests with proper serialization.

JSON-RPC 2.0 Request Structure

A valid JSON-RPC 2.0 request contains:

  • jsonrpc: Protocol version (always "2.0")

  • id: Unique identifier for matching requests to responses

  • method: Name of the RPC method to invoke

  • params: Method-specific parameters (optional, can be null)

Example Usage

// Create a request to get health status
val request = SorobanRpcRequest(
id = "1",
method = "getHealth",
params = null
)

// Create a request with parameters
val ledgerRequest = SorobanRpcRequest(
id = "2",
method = "getLedgerEntries",
params = GetLedgerEntriesRequest(keys = listOf("..."))
)

Serialization

This class uses kotlinx.serialization for JSON encoding/decoding. The jsonrpc field is serialized as "jsonrpc" (not "jsonRpc") to comply with the JSON-RPC specification.

Parameters

T

The type of the request parameters (can be nullable for parameter-less methods)

See also

Constructors

Link copied to clipboard
constructor(jsonRpc: String = "2.0", id: String, method: String, params: T? = null)

Properties

Link copied to clipboard
val id: String

Unique identifier for this request.

Link copied to clipboard
@SerialName(value = "jsonrpc")
val jsonRpc: String

JSON-RPC protocol version.

Link copied to clipboard

The RPC method name to invoke.

Link copied to clipboard
val params: T?

Method-specific parameters.