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
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
VERSION_NR
public
mixed
VERSION_NR
= "1.9.1"
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
Return values
bool —True if the account exists, false otherwise
accounts()
Returns a request builder for querying account data
public
accounts() : AccountsRequestBuilder
Return values
AccountsRequestBuilder —Builder for constructing account queries
assets()
Returns a request builder for querying asset data
public
assets() : AssetsRequestBuilder
Return values
AssetsRequestBuilder —Builder for constructing asset queries
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
Return values
string|false —The account ID of the first destination requiring a memo, or false if none found
claimableBalances()
Returns a request builder for querying claimable balances
public
claimableBalances() : ClaimableBalancesRequestBuilder
Return values
ClaimableBalancesRequestBuilder —Builder for constructing claimable balance queries
effects()
Returns a request builder for querying account effects
public
effects() : EffectsRequestBuilder
Return values
EffectsRequestBuilder —Builder for constructing effect queries
feeStats()
Returns a request builder for querying fee statistics
public
feeStats() : FeeStatsRequestBuilder
Return values
FeeStatsRequestBuilder —Builder for constructing fee stats queries
findPaths()
Returns a request builder for finding payment paths
public
findPaths() : FindPathsRequestBuilder
Return values
FindPathsRequestBuilder —Builder for finding payment paths between assets
findStrictReceivePaths()
Returns a request builder for finding strict receive payment paths
public
findStrictReceivePaths() : StrictReceivePathsRequestBuilder
Return values
StrictReceivePathsRequestBuilder —Builder for finding paths with fixed destination amount
findStrictSendPaths()
Returns a request builder for finding strict send payment paths
public
findStrictSendPaths() : StrictSendPathsRequestBuilder
Return values
StrictSendPathsRequestBuilder —Builder for finding paths with fixed source amount
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
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
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
Return values
HealthResponse —Current health status of the Horizon server
ledgers()
Returns a request builder for querying ledger data
public
ledgers() : LedgersRequestBuilder
Return values
LedgersRequestBuilder —Builder for constructing ledger queries
liquidityPools()
Returns a request builder for querying liquidity pools
public
liquidityPools() : LiquidityPoolsRequestBuilder
Return values
LiquidityPoolsRequestBuilder —Builder for constructing liquidity pool queries
offers()
Returns a request builder for querying offers
public
offers() : OffersRequestBuilder
Return values
OffersRequestBuilder —Builder for constructing offer queries
operations()
Returns a request builder for querying operation data
public
operations() : OperationsRequestBuilder
Return values
OperationsRequestBuilder —Builder for constructing operation queries
orderBook()
Returns a request builder for querying order book data
public
orderBook() : OrderBookRequestBuilder
Return values
OrderBookRequestBuilder —Builder for constructing order book queries
payments()
Returns a request builder for querying payment operations
public
payments() : PaymentsRequestBuilder
Return values
PaymentsRequestBuilder —Builder for constructing payment queries
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
Return values
AccountResponse —Account details including balances, sequence number, and signers
requestClaimableBalance()
Requests the claimable balance details from horizon for the given claimable balance id
public
requestClaimableBalance(string $claimableBalanceId) : ClaimableBalanceResponse
Parameters
- $claimableBalanceId : string
-
The id of the claimable balance to request.
Tags
Return values
ClaimableBalanceResponse —The claimable balance details.
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
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
Return values
LedgerResponse —Ledger details including transaction count and close time
requestLiquidityPool()
Requests the liquidity pool details from horizon for the given pool id.
public
requestLiquidityPool(string $poolId) : LiquidityPoolResponse
Parameters
- $poolId : string
-
The id of the pool to request.
Tags
Return values
LiquidityPoolResponse —The details of the pool.
requestOffer()
Requests the offer details from horizon for the given offer id.
public
requestOffer(string $offerId) : OfferResponse
Parameters
- $offerId : string
-
The id of the offer to request.
Tags
Return values
OfferResponse —The details of the offer.
requestOperation()
Requests the operation details for the given operation id.
public
requestOperation(string $operationId) : OperationResponse
Parameters
- $operationId : string
-
The operation id for the request.
Tags
Return values
OperationResponse —The operation details.
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
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
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
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
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
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
Return values
SubmitTransactionResponse —the response received from Horizon.
tradeAggregations()
Returns a request builder for querying aggregated trade data
public
tradeAggregations() : TradeAggregationsRequestBuilder
Return values
TradeAggregationsRequestBuilder —Builder for constructing trade aggregation queries
trades()
Returns a request builder for querying trade data
public
trades() : TradesRequestBuilder
Return values
TradesRequestBuilder —Builder for constructing trade queries
transactions()
Returns a request builder for querying transaction data
public
transactions() : TransactionsRequestBuilder
Return values
TransactionsRequestBuilder —Builder for constructing transaction queries