Stellar PHP SDK API Documentation

TransactionsRequestBuilder extends RequestBuilder

Builds requests for the transactions endpoint in Horizon

This class provides methods to query transactions on the Stellar network, including fetching individual transactions, querying transactions for specific accounts, ledgers, or liquidity pools, and streaming real-time transaction updates.

Transactions represent operations that have been submitted to and processed by the network. Each transaction contains one or more operations and is signed by one or more accounts.

Query Methods:

  • forAccount(): Get transactions for a specific account
  • forLedger(): Get transactions in a specific ledger
  • forClaimableBalance(): Get transactions involving a claimable balance
  • forLiquidityPool(): Get transactions involving a liquidity pool
  • includeFailed(): Include failed transactions in results

Usage Examples:

// Get a single transaction $tx = $sdk->transactions()->transaction("hash123...");

// Get transactions for an account with pagination $txs = $sdk->transactions() ->forAccount("GDAT5...") ->limit(20) ->order("desc") ->execute();

// Include failed transactions $txs = $sdk->transactions() ->forAccount("GDAT5...") ->includeFailed(true) ->execute();

// Stream real-time transactions $sdk->transactions() ->cursor("now") ->stream(function($tx) { echo "New transaction: " . $tx->getHash(); });

Tags
see
https://developers.stellar.org

Stellar developer docs Transactions API documentation

Table of Contents

Constants

HEADERS  = ["X-Client-Name" => "stellar_php_sdk", "X-Client-Version" => \Soneso\StellarSDK\StellarSDK::VERSION_NR]

Properties

$httpClient  : Client
$queryParameters  : array<string|int, mixed>
$segments  : array<string|int, mixed>

Methods

__construct()  : mixed
Constructs a new TransactionsRequestBuilder instance
buildUrl()  : string
Builds the complete request URL with all segments and query parameters
cursor()  : TransactionsRequestBuilder
Sets the cursor position for pagination
execute()  : TransactionsPageResponse
Builds the query URL and executes the request
executeRequest()  : Response
Executes an HTTP request to Horizon and returns a parsed response object
forAccount()  : TransactionsRequestBuilder
Filters transactions to those affecting a specific account
forClaimableBalance()  : TransactionsRequestBuilder
Filters transactions to those affecting a specific claimable balance
forLedger()  : TransactionsRequestBuilder
Filters transactions to those in a specific ledger
forLiquidityPool()  : TransactionsRequestBuilder
Filters transactions to those affecting a specific liquidity pool
getAndStream()  : void
Streams Server-Sent Events from Horizon to a callback function
includeFailed()  : TransactionsRequestBuilder
Includes failed transactions in the results
limit()  : TransactionsRequestBuilder
Sets the maximum number of transactions to return
order()  : TransactionsRequestBuilder
Sets the sort order for results
request()  : TransactionsPageResponse
Requests a specific URL and returns paginated transactions
stream()  : void
Streams real-time transaction updates to a callback function
transaction()  : TransactionResponse
Fetches a single transaction by its hash
setSegments()  : RequestBuilder
Sets the URL path segments for this request

Constants

HEADERS

public mixed HEADERS = ["X-Client-Name" => "stellar_php_sdk", "X-Client-Version" => \Soneso\StellarSDK\StellarSDK::VERSION_NR]

Properties

$queryParameters

protected array<string|int, mixed> $queryParameters

Methods

__construct()

Constructs a new TransactionsRequestBuilder instance

public __construct(Client $httpClient) : mixed
Parameters
$httpClient : Client

The Guzzle HTTP client for making requests

buildUrl()

Builds the complete request URL with all segments and query parameters

public buildUrl() : string

Combines the URL path segments with query parameters to create the final request URL string that will be sent to Horizon.

Return values
string

The constructed URL with query parameters

cursor()

Sets the cursor position for pagination

public cursor(string $cursor) : TransactionsRequestBuilder

A cursor is an opaque value that points to a specific location in a result set. Use "now" as the cursor to stream only new transactions.

Parameters
$cursor : string

The paging token from a previous response or "now"

Tags
see
https://developers.stellar.org

Stellar developer docs Pagination documentation

Return values
TransactionsRequestBuilder

This instance for method chaining

executeRequest()

Executes an HTTP request to Horizon and returns a parsed response object

public executeRequest(string $url, string $requestType[, string|null $requestMethod = "GET" ]) : Response

This method sends the HTTP request to the Horizon server, handles errors, and parses the JSON response into the appropriate response type.

Parameters
$url : string

The complete request URL to fetch

$requestType : string

The expected response type for parsing

$requestMethod : string|null = "GET"

The HTTP method to use (default: "GET")

Tags
throws
HorizonRequestException

If the request fails or response cannot be parsed

Return values
Response

The parsed response object of the specified type

forAccount()

Filters transactions to those affecting a specific account

public forAccount(string $accountId) : TransactionsRequestBuilder

Returns transactions where the specified account is either the source account or affected by one of the transaction's operations.

Builds request to GET /accounts/{account}/transactions

Parameters
$accountId : string

Public key of the account to filter by (G-address)

Tags
see
https://developers.stellar.org

Stellar developer docs Transactions for Account

Return values
TransactionsRequestBuilder

This instance for method chaining

forClaimableBalance()

Filters transactions to those affecting a specific claimable balance

public forClaimableBalance(string $claimableBalanceId) : TransactionsRequestBuilder

Returns transactions that created, claimed, or clawed back the specified claimable balance.

Builds request to GET /claimable_balances/{claimable_balance_id}/transactions

Parameters
$claimableBalanceId : string

ID of the claimable balance (B-address or hex format)

Tags
see
https://developers.stellar.org

Stellar developer docs Transactions for ClaimableBalance

Return values
TransactionsRequestBuilder

This instance for method chaining

forLedger()

Filters transactions to those in a specific ledger

public forLedger(string $ledgerSeq) : TransactionsRequestBuilder

Returns all transactions that were included in the specified ledger.

Builds request to GET /ledgers/{ledgerSeq}/transactions

Parameters
$ledgerSeq : string

The ledger sequence number

Tags
see
https://developers.stellar.org

Stellar developer docs Transactions for Ledger

Return values
TransactionsRequestBuilder

This instance for method chaining

forLiquidityPool()

Filters transactions to those affecting a specific liquidity pool

public forLiquidityPool(string $liquidityPoolId) : TransactionsRequestBuilder

Returns transactions that deposited to, withdrew from, or traded with the specified liquidity pool.

Builds request to GET /liquidity_pools/{poolID}/transactions

Parameters
$liquidityPoolId : string

The liquidity pool ID (L-address or hex format)

Tags
see
https://developers.stellar.org

Stellar developer docs Transactions for Liquidity Pool

Return values
TransactionsRequestBuilder

This instance for method chaining

getAndStream()

Streams Server-Sent Events from Horizon to a callback function

public getAndStream(string $relativeUrl, callable $callback[, bool $retryOnServerException = true ]) : void

This method establishes a persistent connection to Horizon's streaming endpoints using Server-Sent Events (SSE). It processes each event and passes the parsed data to the provided callback function. The stream automatically reconnects on server exceptions if retryOnServerException is true.

Horizon streaming uses SSE to push real-time updates. The stream sends:

  • "hello" message on connection
  • "byebye" message on disconnection
  • JSON data objects for actual events
Parameters
$relativeUrl : string

The relative URL to stream from

$callback : callable

Function to receive parsed event data

$retryOnServerException : bool = true

If true, automatically retry on server errors (default: true)

Tags
throws
GuzzleException

If a network error occurs and retryOnServerException is false

Return values
void

This method runs indefinitely until interrupted

includeFailed()

Includes failed transactions in the results

public includeFailed(bool $value) : TransactionsRequestBuilder

By default, only successful transactions are returned. Set this to true to also include transactions that failed during execution.

Parameters
$value : bool

Set to true to include failed transactions, false to exclude them

Return values
TransactionsRequestBuilder

This instance for method chaining

order()

Sets the sort order for results

public order([string $direction = "asc" ]) : TransactionsRequestBuilder

Determines whether results are sorted by ledger sequence in ascending or descending order.

Parameters
$direction : string = "asc"

Sort direction: "asc" for ascending, "desc" for descending

Return values
TransactionsRequestBuilder

This instance for method chaining

stream()

Streams real-time transaction updates to a callback function

public stream([callable|null $callback = null ]) : void

This method establishes a persistent connection to Horizon and streams new transactions as they are added to the network. The callback is invoked for each new transaction.

Use cursor("now") before calling stream() to only receive new transactions and skip historical ones.

Example: $sdk->transactions()->cursor("now")->stream(function(TransactionResponse $tx) { printf("New transaction: %s\n", $tx->getHash()); });

Parameters
$callback : callable|null = null

Function to receive TransactionResponse objects

Tags
throws
GuzzleException

If the streaming connection fails

Return values
void

This method runs indefinitely until interrupted

setSegments()

Sets the URL path segments for this request

protected setSegments(string ...$segments) : RequestBuilder

This method constructs the URL path by combining multiple segments. Can only be called once per request builder instance.

Parameters
$segments : string

Variable number of URL path segments

Tags
throws
RuntimeException

If segments have already been set

Return values
RequestBuilder

This instance for method chaining


        
On this page

Search results