Stellar PHP SDK API Documentation

OperationsRequestBuilder extends RequestBuilder

Builds requests for the operations endpoint in Horizon

This class provides methods to query operations on the Stellar network. Operations are individual actions within transactions, such as payments, account creation, trustline management, and trades.

Query Methods:

  • forAccount(): Get operations for a specific account
  • forLedger(): Get operations in a specific ledger
  • forTransaction(): Get operations in a specific transaction
  • forClaimableBalance(): Get operations affecting a claimable balance
  • forLiquidityPool(): Get operations affecting a liquidity pool
  • includeFailed(): Include operations from failed transactions
  • includeTransactions(): Include full transaction data in responses

Usage Examples:

// Get a single operation $operation = $sdk->operations()->operation("123456789");

// Get operations for an account $operations = $sdk->operations() ->forAccount("GDAT5...") ->limit(50) ->order("desc") ->execute();

// Get operations with transaction data $operations = $sdk->operations() ->forAccount("GDAT5...") ->includeTransactions(true) ->execute();

// Stream real-time operations $sdk->operations() ->cursor("now") ->stream(function($op) { echo "Operation type: " . $op->getType(); });

Tags
see
https://developers.stellar.org

Stellar developer docs Operations 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 OperationsRequestBuilder instance
buildUrl()  : string
Builds the complete request URL with all segments and query parameters
cursor()  : OperationsRequestBuilder
Sets the cursor position for pagination
execute()  : OperationsPageResponse
Builds the query URL and executes the request
executeRequest()  : Response
Executes an HTTP request to Horizon and returns a parsed response object
forAccount()  : OperationsRequestBuilder
Filters operations to those affecting a specific account
forClaimableBalance()  : OperationsRequestBuilder
Filters operations to those affecting a specific claimable balance
forLedger()  : OperationsRequestBuilder
Filters operations to those in a specific ledger
forLiquidityPool()  : OperationsRequestBuilder
Filters operations to those affecting a specific liquidity pool
forTransaction()  : OperationsRequestBuilder
Filters operations to those in a specific transaction
getAndStream()  : void
Streams Server-Sent Events from Horizon to a callback function
includeFailed()  : OperationsRequestBuilder
Includes operations from failed transactions in the results
includeTransactions()  : OperationsRequestBuilder
Includes full transaction data in operation responses
limit()  : OperationsRequestBuilder
Sets the maximum number of operations to return
operation()  : OperationResponse
Fetches a single operation by its ID
order()  : OperationsRequestBuilder
Sets the sort order for results
request()  : OperationsPageResponse
Requests a specific URL and returns paginated operations
stream()  : void
Streams real-time operation updates to a callback function
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 OperationsRequestBuilder 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) : OperationsRequestBuilder

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 operations.

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
OperationsRequestBuilder

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 operations to those affecting a specific account

public forAccount(string $accountId) : OperationsRequestBuilder

Returns operations where the specified account is involved as source, destination, or affected by the operation.

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

Parameters
$accountId : string

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

Tags
see
https://developers.stellar.org

Stellar developer docs Operations for Account

Return values
OperationsRequestBuilder

This instance for method chaining

forClaimableBalance()

Filters operations to those affecting a specific claimable balance

public forClaimableBalance(string $claimableBalanceId) : OperationsRequestBuilder

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

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

Parameters
$claimableBalanceId : string

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

Tags
see
https://developers.stellar.org

Stellar developer docs Operations for ClaimableBalance

Return values
OperationsRequestBuilder

This instance for method chaining

forLedger()

Filters operations to those in a specific ledger

public forLedger(string $ledgerSeq) : OperationsRequestBuilder

Returns all operations that were executed in the specified ledger.

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

Parameters
$ledgerSeq : string

The ledger sequence number

Tags
see
https://developers.stellar.org

Stellar developer docs Operations for Ledger

Return values
OperationsRequestBuilder

This instance for method chaining

forLiquidityPool()

Filters operations to those affecting a specific liquidity pool

public forLiquidityPool(string $liquidityPoolId) : OperationsRequestBuilder

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

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

Parameters
$liquidityPoolId : string

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

Tags
see
https://developers.stellar.org

Stellar developer docs Operations for Liquidity Pool

Return values
OperationsRequestBuilder

This instance for method chaining

forTransaction()

Filters operations to those in a specific transaction

public forTransaction(string $transactionId) : OperationsRequestBuilder

Returns all operations that are part of the specified transaction.

Builds request to GET /transactions/{transactionId}/operations

Parameters
$transactionId : string

The transaction hash

Tags
see
https://developers.stellar.org

Stellar developer docs Operations for Transaction

Return values
OperationsRequestBuilder

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 operations from failed transactions in the results

public includeFailed(bool $value) : OperationsRequestBuilder

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

Parameters
$value : bool

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

Return values
OperationsRequestBuilder

This instance for method chaining

includeTransactions()

Includes full transaction data in operation responses

public includeTransactions(bool $include) : OperationsRequestBuilder

By default, operation responses only contain a link to the transaction. Set this to true to embed the complete transaction data in each operation response.

Parameters
$include : bool

Set to true to include transaction data, false to exclude

Return values
OperationsRequestBuilder

This instance for method chaining

limit()

Sets the maximum number of operations to return

public limit(int $number) : OperationsRequestBuilder

Defines the maximum number of records in the response. Maximum allowed is typically 200.

Parameters
$number : int

Maximum number of operations to return (1-200)

Return values
OperationsRequestBuilder

This instance for method chaining

order()

Sets the sort order for results

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

Determines whether results are sorted by operation ID in ascending or descending order.

Parameters
$direction : string = "asc"

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

Return values
OperationsRequestBuilder

This instance for method chaining

stream()

Streams real-time operation updates to a callback function

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

This method establishes a persistent connection to Horizon and streams new operations as they occur on the network. The callback is invoked for each new operation.

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

Example: $sdk->operations()->cursor("now")->stream(function(OperationResponse $operation) { printf("Operation ID: %s, Type: %s\n", $operation->getId(), $operation->getType()); });

Parameters
$callback : callable|null = null

Function to receive OperationResponse 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