Stellar PHP SDK API Documentation

StellarSDK
in package

Main entry point for interacting with Stellar Horizon servers

This class provides a high-level interface for accessing Stellar network data and submitting transactions through a Horizon server. It manages HTTP client connections, provides convenient access to all Horizon API endpoints, and includes helper methods for common operations like checking account existence and validating memo requirements.

Usage: // Connect to public network $sdk = StellarSDK::getPublicNetInstance();

// Or connect to testnet $sdk = StellarSDK::getTestNetInstance();

// Or connect to a custom Horizon server $sdk = new StellarSDK("https://horizon-custom.example.com");

// Request account details $account = $sdk->requestAccount("GABC...");

// Submit a transaction $response = $sdk->submitTransaction($transaction);

Tags
see
https://developers.stellar.org

Stellar developer docs Horizon API Documentation

since
1.0.0

Table of Contents

Constants

VERSION_NR  = "1.9.1"

Properties

$FUTURE_NET_HORIZON_URL  : string
$PUBLIC_NET_HORIZON_URL  : string
$TEST_NET_HORIZON_URL  : string

Methods

__construct()  : mixed
Creates a new StellarSDK instance connected to the specified Horizon server
accountExists()  : bool
Checks if an account exists on the Stellar network
accounts()  : AccountsRequestBuilder
Returns a request builder for querying account data
assets()  : AssetsRequestBuilder
Returns a request builder for querying asset data
checkMemoRequired()  : string|false
Validates memo requirements according to SEP-0029 specification
claimableBalances()  : ClaimableBalancesRequestBuilder
Returns a request builder for querying claimable balances
effects()  : EffectsRequestBuilder
Returns a request builder for querying account effects
feeStats()  : FeeStatsRequestBuilder
Returns a request builder for querying fee statistics
findPaths()  : FindPathsRequestBuilder
Returns a request builder for finding payment paths
findStrictReceivePaths()  : StrictReceivePathsRequestBuilder
Returns a request builder for finding strict receive payment paths
findStrictSendPaths()  : StrictSendPathsRequestBuilder
Returns a request builder for finding strict send payment paths
getFutureNetInstance()  : StellarSDK
Returns a singleton instance connected to the Stellar future network
getHttpClient()  : Client
Returns the underlying Guzzle HTTP client used for Horizon requests
getPublicNetInstance()  : StellarSDK
Returns a singleton instance connected to the Stellar public network
getTestNetInstance()  : StellarSDK
Returns a singleton instance connected to the Stellar test network
health()  : HealthResponse
Requests the health status of the Horizon server
ledgers()  : LedgersRequestBuilder
Returns a request builder for querying ledger data
liquidityPools()  : LiquidityPoolsRequestBuilder
Returns a request builder for querying liquidity pools
offers()  : OffersRequestBuilder
Returns a request builder for querying offers
operations()  : OperationsRequestBuilder
Returns a request builder for querying operation data
orderBook()  : OrderBookRequestBuilder
Returns a request builder for querying order book data
payments()  : PaymentsRequestBuilder
Returns a request builder for querying payment operations
requestAccount()  : AccountResponse
Requests account details from Horizon for the specified account ID
requestClaimableBalance()  : ClaimableBalanceResponse
Requests the claimable balance details from horizon for the given claimable balance id
requestFeeStats()  : FeeStatsResponse
Requests current fee statistics from Horizon
requestLedger()  : LedgerResponse
Requests ledger details from Horizon for the specified ledger sequence
requestLiquidityPool()  : LiquidityPoolResponse
Requests the liquidity pool details from horizon for the given pool id.
requestOffer()  : OfferResponse
Requests the offer details from horizon for the given offer id.
requestOperation()  : OperationResponse
Requests the operation details for the given operation id.
requestTransaction()  : TransactionResponse
Requests transaction details from Horizon for the specified transaction hash
root()  : RootResponse
Requests root information from the Horizon server
setHttpClient()  : void
Sets a custom Guzzle HTTP client for Horizon requests
submitAsyncTransaction()  : SubmitAsyncTransactionResponse
Submits an asynchronous transaction to the network. Unlike the synchronous version 'submitTransaction', which blocks and waits for the transaction to be ingested in Horizon, this endpoint relays the response from core directly back to the user.
submitAsyncTransactionEnvelopeXdrBase64()  : SubmitAsyncTransactionResponse
Submits an asynchronous transaction envelope xdr base 64 string to the network.
submitTransaction()  : SubmitTransactionResponse
Submits a synchronous transaction to the network. Unlike the asynchronous version 'submitAsyncTransaction', which relays the response from core directly back to the user, this endpoint blocks and waits for the transaction to be ingested in Horizon.
submitTransactionEnvelopeXdrBase64()  : SubmitTransactionResponse
Submits a synchronous transaction envelope xdr base 64 string to the network.
tradeAggregations()  : TradeAggregationsRequestBuilder
Returns a request builder for querying aggregated trade data
trades()  : TradesRequestBuilder
Returns a request builder for querying trade data
transactions()  : TransactionsRequestBuilder
Returns a request builder for querying transaction data

Constants

Properties

$FUTURE_NET_HORIZON_URL

public static string $FUTURE_NET_HORIZON_URL = "https://horizon-futurenet.stellar.org"

$PUBLIC_NET_HORIZON_URL

public static string $PUBLIC_NET_HORIZON_URL = "https://horizon.stellar.org"

$TEST_NET_HORIZON_URL

public static string $TEST_NET_HORIZON_URL = "https://horizon-testnet.stellar.org"

Methods

__construct()

Creates a new StellarSDK instance connected to the specified Horizon server

public __construct(string $uri) : mixed
Parameters
$uri : string

The base URI of the Horizon server (e.g., "https://horizon.stellar.org")

accountExists()

Checks if an account exists on the Stellar network

public accountExists(string $accountId) : bool

This is a convenience method that returns false if the account is not found instead of throwing an exception.

Parameters
$accountId : string

The account ID (public key) to check

Tags
throws
HorizonRequestException

If the request fails for reasons other than account not found

Return values
bool

True if the account exists, false otherwise

checkMemoRequired()

Validates memo requirements according to SEP-0029 specification

public checkMemoRequired(AbstractTransaction $transaction) : string|false

SEP-0029 allows account owners to require that incoming payments include a memo. This method checks if any destination accounts in the transaction require a memo and returns the first account ID that requires one if the transaction lacks a memo.

Parameters
$transaction : AbstractTransaction

The transaction to validate

Tags
throws
HorizonRequestException

If the request to check account data fails

see
https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0029.md
Return values
string|false

The account ID of the first destination requiring a memo, or false if none found

getFutureNetInstance()

Returns a singleton instance connected to the Stellar future network

public static getFutureNetInstance() : StellarSDK

This network is used for testing upcoming protocol features before they are released to testnet or the public network. Use with caution as this network may undergo frequent resets.

Tags
see
https://developers.stellar.org

Stellar developer docs

Return values
StellarSDK

Singleton instance configured for the future network

getHttpClient()

Returns the underlying Guzzle HTTP client used for Horizon requests

public getHttpClient() : Client
Return values
Client

The configured HTTP client

getPublicNetInstance()

Returns a singleton instance connected to the Stellar public network

public static getPublicNetInstance() : StellarSDK

This is the main production Stellar network. Use this for real transactions involving actual assets with value.

Return values
StellarSDK

Singleton instance configured for the public network

getTestNetInstance()

Returns a singleton instance connected to the Stellar test network

public static getTestNetInstance() : StellarSDK

Use this network for testing and development. Accounts can be funded using the friendbot service and testnet assets have no real-world value.

Tags
see
https://developers.stellar.org

Stellar developer docs

Return values
StellarSDK

Singleton instance configured for the test network

health()

Requests the health status of the Horizon server

public health() : HealthResponse

Returns health information including whether the Horizon server is in sync with the Stellar network and ready to serve requests.

Tags
throws
HorizonRequestException

If the request fails

Return values
HealthResponse

Current health status of the Horizon server

requestAccount()

Requests account details from Horizon for the specified account ID

public requestAccount(string $accountId) : AccountResponse
Parameters
$accountId : string

The account ID (public key starting with G) to query

Tags
throws
HorizonRequestException

If the account is not found or the request fails

Return values
AccountResponse

Account details including balances, sequence number, and signers

requestFeeStats()

Requests current fee statistics from Horizon

public requestFeeStats() : FeeStatsResponse

Fee stats provide information about recent transaction fees including minimum, maximum, and percentile-based fee recommendations for different priority levels.

Tags
throws
HorizonRequestException

If the request fails

Return values
FeeStatsResponse

Current network fee statistics

requestLedger()

Requests ledger details from Horizon for the specified ledger sequence

public requestLedger(string $ledgerSeq) : LedgerResponse
Parameters
$ledgerSeq : string

The ledger sequence number to query

Tags
throws
HorizonRequestException

If the ledger is not found or the request fails

Return values
LedgerResponse

Ledger details including transaction count and close time

requestTransaction()

Requests transaction details from Horizon for the specified transaction hash

public requestTransaction(string $transactionId) : TransactionResponse
Parameters
$transactionId : string

The transaction hash to query

Tags
throws
HorizonRequestException

If the transaction is not found or the request fails

Return values
TransactionResponse

Transaction details including operations and result

root()

Requests root information from the Horizon server

public root() : RootResponse

The root endpoint provides metadata about the Horizon server including supported protocol versions, network passphrase, and available endpoints.

Tags
throws
HorizonRequestException

If the request fails

Return values
RootResponse

Server metadata and capabilities

setHttpClient()

Sets a custom Guzzle HTTP client for Horizon requests

public setHttpClient(Client $httpClient) : void

Use this to configure custom timeout, proxy, or middleware settings.

Parameters
$httpClient : Client

The HTTP client to use for subsequent requests

submitAsyncTransaction()

Submits an asynchronous transaction to the network. Unlike the synchronous version 'submitTransaction', which blocks and waits for the transaction to be ingested in Horizon, this endpoint relays the response from core directly back to the user.

public submitAsyncTransaction(AbstractTransaction $transaction) : SubmitAsyncTransactionResponse
Parameters
$transaction : AbstractTransaction

the transaction to be submitted.

Tags
throws
HorizonRequestException

if there was a problem, such as an error response from Horizon. The details of the problem can be found within the exception object.

Return values
SubmitAsyncTransactionResponse

the response received from Horizon.

submitAsyncTransactionEnvelopeXdrBase64()

Submits an asynchronous transaction envelope xdr base 64 string to the network.

public submitAsyncTransactionEnvelopeXdrBase64(string $transactionEnvelopeXdrBase64) : SubmitAsyncTransactionResponse

Unlike the synchronous version 'submitTransactionEnvelopeXdrBase64', which blocks and waits for the transaction to be ingested in Horizon, this endpoint relays the response from core directly back to the user.

Parameters
$transactionEnvelopeXdrBase64 : string

transaction envelope xdr base 64 string to be submitted to the network.

Tags
throws
HorizonRequestException

if there was a problem, such as an error response from Horizon. The details of the problem can be found within the exception object.

Return values
SubmitAsyncTransactionResponse

the response received from Horizon.

submitTransaction()

Submits a synchronous transaction to the network. Unlike the asynchronous version 'submitAsyncTransaction', which relays the response from core directly back to the user, this endpoint blocks and waits for the transaction to be ingested in Horizon.

public submitTransaction(AbstractTransaction $transaction) : SubmitTransactionResponse
Parameters
$transaction : AbstractTransaction

the transaction to be submitted.

Tags
throws
HorizonRequestException

if there was a problem, such as an error response from Horizon. The details of the problem can be found within the exception object.

Return values
SubmitTransactionResponse

the response received from Horizon.

submitTransactionEnvelopeXdrBase64()

Submits a synchronous transaction envelope xdr base 64 string to the network.

public submitTransactionEnvelopeXdrBase64(string $transactionEnvelopeXdrBase64) : SubmitTransactionResponse

Unlike the asynchronous version 'submitAsyncTransactionEnvelopeXdrBase64', which relays the response from core directly back to the user, this endpoint blocks and waits for the transaction to be ingested in Horizon.

Parameters
$transactionEnvelopeXdrBase64 : string

transaction envelope xdr base 64 string to be submitted to the network.

Tags
throws
HorizonRequestException

if there was a problem, such as an error response from Horizon. The details of the problem can be found within the exception object.

Return values
SubmitTransactionResponse

the response received from Horizon.


        
On this page

Search results