Soroban Server
Main client class for connecting to a Soroban RPC instance and making requests.
Soroban RPC is Stellar's smart contract platform RPC server that provides APIs to:
Simulate and submit smart contract transactions
Query contract state and ledger entries
Monitor transaction status and events
Fetch network metadata and fee statistics
JSON-RPC 2.0 Protocol
All Soroban RPC methods use JSON-RPC 2.0 over HTTP. This client handles:
Request/response serialization
Error handling and exception mapping
Automatic request ID generation
HTTP connection management
Basic Usage
// Create server instance
val server = SorobanServer("https://soroban-testnet.stellar.org:443")
// Check server health
val health = server.getHealth()
println("Server status: ${health.status}")
// Get account for transaction building
val account = server.getAccount("GABC...")
// Simulate a transaction
val simulation = server.simulateTransaction(transaction)
// Prepare transaction with simulation results
val prepared = server.prepareTransaction(transaction)
// Sign and submit
prepared.sign(keypair)
val response = server.sendTransaction(prepared)
// Poll for completion
val result = server.pollTransaction(response.hash!!)
// Close when done
server.close()Transaction Preparation Flow
Soroban transactions require simulation before submission to:
Calculate resource requirements (CPU, memory, storage)
Determine authorization entries needed
Estimate resource fees
The typical flow is:
Build transaction with com.soneso.stellar.sdk.TransactionBuilder
Call simulateTransaction to get resource estimates
Call prepareTransaction to apply estimates to transaction
Sign the prepared transaction
Submit with sendTransaction
Poll for completion with pollTransaction
Or use the simplified flow:
val prepared = server.prepareTransaction(transaction) // Simulates internally
prepared.sign(keypair)
val response = server.sendTransaction(prepared)Resource Management
This class implements AutoCloseable and should be closed when no longer needed to release HTTP client resources:
SorobanServer(url).use { server ->
// Use server
}Error Handling
Methods throw:
SorobanRpcException - RPC-level errors (server returns error response)
PrepareTransactionException - Transaction preparation failures
kotlinx.coroutines.TimeoutCancellationException - Request timeout
Exception - Network/connection errors
See also
Functions
Fetches a minimal set of current info about a Stellar account.
Reads contract data for a specific key.
Fetches all events matching the given filters.
Gets statistics for charged inclusion fees.
Performs a general node health check.
Fetches the latest ledger metadata.
Reads the current value of ledger entries directly.
Gets a paginated list of ledgers.
Fetches metadata about the network.
Fetches the balance of a Stellar Asset Contract (SAC).
Fetches the details of a submitted transaction.
Gets a paginated list of transactions.
Fetches version information about the RPC server and Captive Core.
Loads the contract code entry (including WASM bytecode) for a given contract ID.
Loads the contract code entry (including WASM bytecode) for a given WASM ID.
Loads contract information (Environment Meta, Contract Spec, Contract Meta) for a given contract ID.
Loads contract information (Environment Meta, Contract Spec, Contract Meta) for a given WASM ID.
Polls for transaction completion.
Prepares a transaction by simulating it and applying resource estimates.
Prepares a transaction using existing simulation results.
Submits a transaction to the Stellar network.
Simulates a transaction to preview its effects.