Stellar PHP SDK API Documentation

SorobanClient

High-level client for interacting with deployed Soroban smart contracts

This class provides a convenient interface for calling contract methods, deploying contracts, and installing contract code. It automatically handles contract spec parsing, type conversion, transaction building, simulation, and signing.

The client is initialized with contract specification entries that define the available methods and types. These specs are extracted from the contract's WASM bytecode and enable type-safe method invocation with automatic conversion between PHP and Soroban types.

Tags
see
AssembledTransaction

For low-level transaction control

see
ContractSpec

For type conversion and spec introspection

see
https://developers.stellar.org/docs/smart-contracts

Soroban Smart Contracts Documentation

since
1.0.0

Table of Contents

Methods

buildInvokeMethodTx()  : AssembledTransaction
Builds a transaction for invoking a contract method without sending it
deploy()  : SorobanClient
Deploys a new contract instance and creates a SorobanClient for it
forClientOptions()  : SorobanClient
Creates a SorobanClient for an existing deployed contract
getContractId()  : string
Retrieves the contract ID of the contract this client represents
getContractSpec()  : ContractSpec
Gets the contract specification utility for type conversion
getMethodNames()  : array<string|int, string>
Retrieves all available method names from the contract
getOptions()  : ClientOptions
Retrieves the client options configuration
getSpecEntries()  : array<string|int, XdrSCSpecEntry>
Retrieves the contract specification entries
install()  : string
Installs contract WASM bytecode to the network
invokeMethod()  : XdrSCVal
Invokes a contract method with automatic read/write detection

Methods

buildInvokeMethodTx()

Builds a transaction for invoking a contract method without sending it

public buildInvokeMethodTx(string $name[, array<string|int, mixed>|null $args = null ][, MethodOptions|null $methodOptions = null ]) : AssembledTransaction

Creates and simulates an AssembledTransaction for the specified method. This is useful when you need to inspect the transaction, sign authorization entries for multi-signature workflows, or manually control the signing and sending process.

Parameters
$name : string

The name of the contract method to invoke

$args : array<string|int, mixed>|null = null

Array of XDR SCVal arguments for the method (optional)

$methodOptions : MethodOptions|null = null

Options for simulation, fees, and timeouts (optional)

Tags
throws
GuzzleException

If the RPC request fails

throws
Exception

If the method does not exist or transaction building fails

Return values
AssembledTransaction

The assembled transaction ready for signing and sending

deploy()

Deploys a new contract instance and creates a SorobanClient for it

public static deploy(DeployRequest $deployRequest) : SorobanClient

Creates a new contract instance from previously installed WASM code, optionally calling the contract's constructor with the provided arguments. Returns a client for the newly deployed contract.

The contract WASM must be installed first using SorobanClient::install.

Parameters
$deployRequest : DeployRequest

Deployment parameters including WASM hash, constructor args, and salt

Tags
throws
Exception

If deployment fails or contract ID cannot be extracted

throws
GuzzleException

If the RPC request fails

Return values
SorobanClient

The client for the newly deployed contract

forClientOptions()

Creates a SorobanClient for an existing deployed contract

public static forClientOptions(ClientOptions $options) : SorobanClient

Loads the contract specification from the network by fetching and parsing the contract's WASM bytecode. The spec is used for type-safe method invocation.

Parameters
$options : ClientOptions

Client configuration including contract ID, network, and RPC URL

Tags
throws
GuzzleException

If the RPC request fails

throws
Exception

If the contract is not found or spec parsing fails

Return values
SorobanClient

The initialized client ready to invoke contract methods

getContractId()

Retrieves the contract ID of the contract this client represents

public getContractId() : string
Return values
string

The C-prefixed contract ID address

getContractSpec()

Gets the contract specification utility for type conversion

public getContractSpec() : ContractSpec

Returns a ContractSpec instance that can be used for advanced type conversion, function argument parsing, and contract introspection.

Return values
ContractSpec

The contract spec utility

getMethodNames()

Retrieves all available method names from the contract

public getMethodNames() : array<string|int, string>

Returns the list of callable function names extracted from the contract specification, excluding the constructor function.

Return values
array<string|int, string>

Array of method names available for invocation

getSpecEntries()

Retrieves the contract specification entries

public getSpecEntries() : array<string|int, XdrSCSpecEntry>
Return values
array<string|int, XdrSCSpecEntry>

Array of parsed spec entries from the contract WASM

install()

Installs contract WASM bytecode to the network

public static install(InstallRequest $installRequest[, bool $force = false ]) : string

Uploads the compiled contract WASM code to the ledger, making it available for deployment. If the code is already installed (detected via simulation), the existing WASM hash is returned without submitting a transaction unless force is true.

Parameters
$installRequest : InstallRequest

Installation parameters including WASM bytes

$force : bool = false

Force transaction submission even if code is already installed (default: false)

Tags
throws
GuzzleException

If the RPC request fails

throws
Exception

If installation fails or WASM hash cannot be extracted

Return values
string

The WASM hash (hex-encoded) of the installed contract code

invokeMethod()

Invokes a contract method with automatic read/write detection

public invokeMethod(string $name[, array<string|int, XdrSCVal>|null $args = null ][, bool $force = false ][, MethodOptions|null $methodOptions = null ]) : XdrSCVal

This is the main method for calling contract functions. It builds and simulates the transaction, and for read-only calls returns the simulation result immediately. For state-changing calls, it signs and sends the transaction, then waits for completion and returns the result.

Read-only calls are detected automatically based on empty authorization and read-write footprint.

Parameters
$name : string

The name of the contract method to invoke

$args : array<string|int, XdrSCVal>|null = null

Array of XDR SCVal arguments for the method (optional)

$force : bool = false

Force signing and sending even for read-only calls (default: false)

$methodOptions : MethodOptions|null = null

Options for simulation, fees, and timeouts (optional)

Tags
throws
GuzzleException

If the RPC request fails

throws
Exception

If the method does not exist or invocation fails

Return values
XdrSCVal

The method return value as an XDR SCVal


        
On this page

Search results