SorobanServer
in package
Main entry point for interacting with Soroban RPC servers
This class provides methods for communicating with a Soroban RPC server to interact with smart contracts on the Stellar network. It handles transaction simulation, submission, ledger queries, event retrieval, and contract code loading. All RPC methods follow the JSON-RPC 2.0 specification and return strongly-typed response objects.
The server handles automatic JSON-RPC request construction and response parsing, converting raw JSON responses into typed PHP objects for type-safe contract interaction.
Tags
Table of Contents
Properties
- $enableLogging : bool
Methods
- __construct() : mixed
- Creates a new Soroban RPC server client
- getAccount() : Account|null
- Retrieves current account information from the ledger
- getContractData() : LedgerEntry|null
- Reads the current value of contract data ledger entries directly.
- getEvents() : GetEventsResponse
- Clients can request a filtered list of events emitted by a given ledger range.
- getFeeStats() : GetFeeStatsResponse
- Statistics for charged inclusion fees. The inclusion fee statistics are calculated from the inclusion fees that were paid for the transactions to be included onto the ledger. For Soroban transactions and Stellar transactions, they each have their own inclusion fees and own surge pricing. Inclusion fees are used to prevent spam and prioritize transactions during network traffic surge.
- getHealth() : GetHealthResponse
- General node health check request.
- getLatestLedger() : GetLatestLedgerResponse
- For finding out the current latest known ledger of this node. This is a subset of the ledger info from Horizon.
- getLedgerEntries() : GetLedgerEntriesResponse
- For reading the current value of ledger entries directly.
- getLedgers() : GetLedgersResponse
- The getLedgers method returns a detailed list of ledgers starting from the user-specified startLedger.
- getNetwork() : GetNetworkResponse
- General information about the currently configured network.
- getTransaction() : GetTransactionResponse
- The getTransaction method provides details about the specified transaction.
- getTransactions() : GetTransactionsResponse
- The getTransactions method returns a detailed list of transactions starting from the user specified starting point that you can paginate as long as the pages fall within the history retention of their corresponding RPC provider.
- getVersionInfo() : GetVersionInfoResponse
- Version information about the RPC and Captive core. RPC manages its own, pared-down version of Stellar Core optimized for its own subset of needs.
- loadContractCodeForContractId() : XdrContractCodeEntry|null
- Loads the contract source code for a given contract id
- loadContractCodeForWasmId() : XdrContractCodeEntry|null
- Loads the contract source code for a given wasm id
- loadContractInfoForContractId() : SorobanContractInfo|null
- Loads and parses contract information for a given contract id
- loadContractInfoForWasmId() : SorobanContractInfo|null
- Loads and parses contract information for a given wasm id
- sendTransaction() : SendTransactionResponse
- Submit a real transaction to the stellar network. This is the only way to make changes “on-chain”.
- simulateTransaction() : SimulateTransactionResponse
- Submit a trial contract invocation to get back return values, expected ledger footprint, and expected costs.
Properties
$enableLogging
public
bool
$enableLogging
= false
Methods
__construct()
Creates a new Soroban RPC server client
public
__construct(string $endpoint) : mixed
Initializes the HTTP client and sets up default headers for JSON-RPC 2.0 communication. The endpoint should be a fully qualified URL to a Soroban RPC server.
Parameters
- $endpoint : string
-
The URL of the Soroban RPC server (e.g., "https://soroban-testnet.stellar.org")
getAccount()
Retrieves current account information from the ledger
public
getAccount(string $accountId) : Account|null
Fetches a minimal set of account data including the current sequence number, which is required for building and submitting transactions. This is more efficient than using Horizon for simple account lookups when working with Soroban.
Parameters
- $accountId : string
-
The account id (G-prefixed address) to query
Tags
Return values
Account|null —The account object with current sequence number, or null if not found
getContractData()
Reads the current value of contract data ledger entries directly.
public
getContractData(string $contractId, XdrSCVal $key, XdrContractDataDurability $durability) : LedgerEntry|null
Parameters
- $contractId : string
-
id of the contract containing the data to load.
- $key : XdrSCVal
-
of the contract data to load.
- $durability : XdrContractDataDurability
-
keyspace that this ledger key belongs to, which is either XdrContractDataDurability::PERSISTENT() or XdrContractDataDurability::TEMPORARY().
Tags
Return values
LedgerEntry|null —Ledger Entry if found otherwise null.
getEvents()
Clients can request a filtered list of events emitted by a given ledger range.
public
getEvents(GetEventsRequest $request) : GetEventsResponse
Soroban-RPC will support querying within a maximum 24 hours of recent ledgers. See: https://developers.stellar.org/docs/data/rpc/api-reference/methods/getEvents
Parameters
- $request : GetEventsRequest
-
containing the request parameters
Tags
Return values
GetEventsResponse —response in case of success.
getFeeStats()
Statistics for charged inclusion fees. The inclusion fee statistics are calculated from the inclusion fees that were paid for the transactions to be included onto the ledger. For Soroban transactions and Stellar transactions, they each have their own inclusion fees and own surge pricing. Inclusion fees are used to prevent spam and prioritize transactions during network traffic surge.
public
getFeeStats() : GetFeeStatsResponse
See: https://developers.stellar.org/docs/data/rpc/api-reference/methods/getFeeStats
Tags
Return values
GetFeeStatsResponse —in case of success.
getHealth()
General node health check request.
public
getHealth() : GetHealthResponse
See: https://developers.stellar.org/docs/data/rpc/api-reference/methods/getHealth
Tags
Return values
GetHealthResponse —in case of success.
getLatestLedger()
For finding out the current latest known ledger of this node. This is a subset of the ledger info from Horizon.
public
getLatestLedger() : GetLatestLedgerResponse
See: https://developers.stellar.org/docs/data/rpc/api-reference/methods/getLatestLedger
Tags
Return values
GetLatestLedgerResponse —response in case of success.
getLedgerEntries()
For reading the current value of ledger entries directly.
public
getLedgerEntries(array<string|int, string> $base64EncodedKeys) : GetLedgerEntriesResponse
Allows you to directly inspect the current state of a contract, a contract’s code, or any other ledger entry. This is a backup way to access your contract data which may not be available via events or simulateTransaction. To fetch contract wasm byte-code, use the ContractCode ledger entry key. See: https://developers.stellar.org/docs/data/rpc/api-reference/methods/getLedgerEntries
Parameters
- $base64EncodedKeys : array<string|int, string>
-
base64-encoded XDR ledger keys to retrieve
Tags
Return values
GetLedgerEntriesResponse —response in case of success.
getLedgers()
The getLedgers method returns a detailed list of ledgers starting from the user-specified startLedger.
public
getLedgers(GetLedgersRequest $request) : GetLedgersResponse
Fetches ledger metadata and header information for a range of ledgers. Supports pagination. See: https://developers.stellar.org/docs/data/rpc/api-reference/methods/getLedgers
Parameters
- $request : GetLedgersRequest
-
The request parameters.
Tags
Return values
GetLedgersResponse —The response containing ledger information.
getNetwork()
General information about the currently configured network.
public
getNetwork() : GetNetworkResponse
The response will contain all the information needed to successfully submit transactions to the network this node serves. See: https://developers.stellar.org/docs/data/rpc/api-reference/methods/getNetwork
Tags
Return values
GetNetworkResponse —in case of success.
getTransaction()
The getTransaction method provides details about the specified transaction.
public
getTransaction(string $transactionId) : GetTransactionResponse
Clients are expected to periodically query this method to ascertain when a transaction has been successfully recorded on the blockchain. See: https://developers.stellar.org/docs/data/rpc/api-reference/methods/getTransaction
Parameters
- $transactionId : string
-
of the transaction to be checked.
Tags
Return values
GetTransactionResponse —response in case of success.
getTransactions()
The getTransactions method returns a detailed list of transactions starting from the user specified starting point that you can paginate as long as the pages fall within the history retention of their corresponding RPC provider.
public
getTransactions(GetTransactionsRequest $request) : GetTransactionsResponse
Parameters
- $request : GetTransactionsRequest
-
request data.
Tags
Return values
GetTransactionsResponse —response in case of success.
getVersionInfo()
Version information about the RPC and Captive core. RPC manages its own, pared-down version of Stellar Core optimized for its own subset of needs.
public
getVersionInfo() : GetVersionInfoResponse
See: https://developers.stellar.org/docs/data/rpc/api-reference/methods/getVersionInfo
Tags
Return values
GetVersionInfoResponse —in case of success.
loadContractCodeForContractId()
Loads the contract source code for a given contract id
public
loadContractCodeForContractId(string $contractId) : XdrContractCodeEntry|null
First retrieves the contract instance data to determine the wasm id, then loads the contract code entry containing the compiled WASM bytecode.
Parameters
- $contractId : string
-
The contract id (C-prefixed address) of the deployed contract
Tags
Return values
XdrContractCodeEntry|null —The contract code entry if found, null if not found
loadContractCodeForWasmId()
Loads the contract source code for a given wasm id
public
loadContractCodeForWasmId(string $wasmId) : XdrContractCodeEntry|null
Retrieves the contract code entry from the ledger, including the compiled WASM bytecode. The wasm id is a hex-encoded hash of the contract bytecode.
Parameters
- $wasmId : string
-
The hex-encoded wasm id (hash) of the contract code
Tags
Return values
XdrContractCodeEntry|null —The contract code entry if found, null if not found
loadContractInfoForContractId()
Loads and parses contract information for a given contract id
public
loadContractInfoForContractId(string $contractId) : SorobanContractInfo|null
Retrieves the contract bytecode from the ledger and parses it to extract metadata including environment meta, contract spec entries, and contract meta information. The contract spec can be used to introspect available functions and types.
Parameters
- $contractId : string
-
The contract id (C-prefixed address) of the deployed contract
Tags
Return values
SorobanContractInfo|null —The parsed contract information or null if contract not found
loadContractInfoForWasmId()
Loads and parses contract information for a given wasm id
public
loadContractInfoForWasmId(string $wasmId) : SorobanContractInfo|null
Retrieves the contract bytecode from the ledger and parses it to extract metadata including environment meta, contract spec entries, and contract meta information. The contract spec can be used to introspect available functions and types.
Parameters
- $wasmId : string
-
The hex-encoded wasm id (hash) of the contract code
Tags
Return values
SorobanContractInfo|null —The parsed contract information or null if contract not found
sendTransaction()
Submit a real transaction to the stellar network. This is the only way to make changes “on-chain”.
public
sendTransaction(Transaction $transaction) : SendTransactionResponse
Unlike Horizon, this does not wait for transaction completion. It simply validates and enqueues the transaction. Clients should call getTransactionStatus to learn about transaction success/failure. See: https://developers.stellar.org/docs/data/rpc/api-reference/methods/sendTransaction
Parameters
- $transaction : Transaction
-
to submit.
Tags
Return values
SendTransactionResponse —response in case of success.
simulateTransaction()
Submit a trial contract invocation to get back return values, expected ledger footprint, and expected costs.
public
simulateTransaction(SimulateTransactionRequest $request) : SimulateTransactionResponse
See: https://developers.stellar.org/docs/data/rpc/api-reference/methods/simulateTransaction
Parameters
- $request : SimulateTransactionRequest
-
request containing the transaction to submit and the resource config.
Tags
Return values
SimulateTransactionResponse —response in case of success.