Transaction
extends AbstractTransaction
in package
Represents a Stellar transaction that contains a set of operations to be executed atomically
A transaction is the fundamental unit of change on the Stellar network. It consists of one or more operations that are executed together or not at all. Each transaction requires a source account, sequence number, and signatures from the required signers.
Usage:
// Build a transaction using the TransactionBuilder
$transaction = (new TransactionBuilder($sourceAccount))
->addOperation($paymentOp)
->addMemo(Memo::text("Payment for invoice"))
->build();
// Sign the transaction $transaction->sign($sourceKeyPair, Network::testnet());
// Submit to the network $response = $sdk->submitTransaction($transaction);
Tags
Table of Contents
Methods
- __construct() : mixed
- Constructor.
- addResourceFee() : void
- Adds a resource fee to the existing transaction fee
- addSignature() : void
- Adds a signature to the transaction
- builder() : TransactionBuilder
- Creates a new TransactionBuilder for constructing transactions
- fromEnvelopeBase64XdrString() : AbstractTransaction
- Creates a transaction from a base64-encoded XDR string
- fromEnvelopeXdr() : AbstractTransaction
- Creates a transaction from an XDR transaction envelope
- fromV0EnvelopeXdr() : Transaction
- Creates a Transaction object from a V0 transaction envelope XDR
- fromV1EnvelopeXdr() : Transaction
- Creates a Transaction object from a V1 transaction envelope XDR
- getFee() : int
- Returns the maximum fee willing to be paid for this transaction in stroops
- getMemo() : Memo
- Returns the memo attached to this transaction
- getOperations() : array<string|int, AbstractOperation>
- Returns all operations included in this transaction
- getPreconditions() : TransactionPreconditions|null
- Returns the transaction preconditions if set
- getSequenceNumber() : BigInteger
- Returns the sequence number for this transaction
- getSignatures() : array<string|int, XdrDecoratedSignature>
- Gets all signatures attached to this transaction
- getSorobanTransactionData() : XdrSorobanTransactionData|null
- Returns the Soroban transaction data if this is a smart contract transaction
- getSourceAccount() : MuxedAccount
- Returns the source account for this transaction
- getTimeBounds() : TimeBounds|null
- Returns the time bounds for this transaction if set
- hash() : string
- Calculates the hash of the transaction for signing
- setFee() : void
- Sets the maximum fee for this transaction in stroops
- setSignatures() : void
- Sets the signatures for this transaction
- setSorobanAuth() : void
- Sets authorization entries for Soroban smart contract invocations
- setSorobanTransactionData() : void
- Sets Soroban transaction data for smart contract transactions
- sign() : void
- Signs the transaction with the provided keypair
- signatureBase() : string
- Generates the signature base for this transaction
- toEnvelopeXdr() : XdrTransactionEnvelope
- Converts this transaction to a complete XDR transaction envelope
- toEnvelopeXdrBase64() : string
- Converts the transaction to base64-encoded XDR envelope format
- toXdr() : XdrTransaction
- Converts this transaction to its XDR representation
- toXdrBase64() : string
- Converts this transaction to base64-encoded XDR
Methods
__construct()
Constructor.
public
__construct(MuxedAccount $sourceAccount, BigInteger $sequenceNumber, array<string|int, AbstractOperation> $operations[, Memo|null $memo = null ][, TransactionPreconditions|null $preconditions = null ][, int|null $fee = null ][, XdrSorobanTransactionData|null $sorobanTransactionData = null ]) : mixed
Parameters
- $sourceAccount : MuxedAccount
-
Source account of the transaction.
- $sequenceNumber : BigInteger
-
Sequence number of the source account.
- $operations : array<string|int, AbstractOperation>
-
Operations to be added to the transaction.
- $memo : Memo|null = null
-
Memo to be added to the transaction.
- $preconditions : TransactionPreconditions|null = null
-
Transaction preconditions if any.
- $fee : int|null = null
-
maximum fee to be paid to the Stellar Network for the transaction. If not set it will be calculated by using the current minimum base fee of currently 100 stoops per operation.
- $sorobanTransactionData : XdrSorobanTransactionData|null = null
-
Soroban transaction data if needed.
Tags
addResourceFee()
Adds a resource fee to the existing transaction fee
public
addResourceFee(int $resourceFee) : void
Used primarily for Soroban smart contract transactions to account for computational and storage resources consumed during execution.
Parameters
- $resourceFee : int
-
Additional resource fee in stroops
addSignature()
Adds a signature to the transaction
public
addSignature(XdrDecoratedSignature $signature) : void
Parameters
- $signature : XdrDecoratedSignature
-
The signature to add
builder()
Creates a new TransactionBuilder for constructing transactions
public
static builder(TransactionBuilderAccount $sourceAccount) : TransactionBuilder
This is the recommended way to build transactions with a fluent interface.
Parameters
- $sourceAccount : TransactionBuilderAccount
-
The source account for the transaction
Tags
Return values
TransactionBuilder —Builder for constructing the transaction
fromEnvelopeBase64XdrString()
Creates a transaction from a base64-encoded XDR string
public
static fromEnvelopeBase64XdrString(string $envelope) : AbstractTransaction
Parameters
- $envelope : string
-
Base64-encoded XDR transaction envelope
Tags
Return values
AbstractTransaction —The decoded transaction (Transaction or FeeBumpTransaction)
fromEnvelopeXdr()
Creates a transaction from an XDR transaction envelope
public
static fromEnvelopeXdr(XdrTransactionEnvelope $envelope) : AbstractTransaction
Parameters
- $envelope : XdrTransactionEnvelope
-
The XDR transaction envelope
Tags
Return values
AbstractTransaction —The decoded transaction (Transaction or FeeBumpTransaction)
fromV0EnvelopeXdr()
Creates a Transaction object from a V0 transaction envelope XDR
public
static fromV0EnvelopeXdr(XdrTransactionV0Envelope $envelope) : Transaction
V0 transactions are the older format. This method converts them to the current Transaction format for compatibility.
Parameters
- $envelope : XdrTransactionV0Envelope
-
The V0 XDR envelope to parse
Return values
Transaction —The reconstructed transaction with signatures
fromV1EnvelopeXdr()
Creates a Transaction object from a V1 transaction envelope XDR
public
static fromV1EnvelopeXdr(XdrTransactionV1Envelope $envelope) : Transaction
Parameters
- $envelope : XdrTransactionV1Envelope
-
The XDR envelope to parse
Return values
Transaction —The reconstructed transaction with signatures
getFee()
Returns the maximum fee willing to be paid for this transaction in stroops
public
getFee() : int
One stroop equals 0.0000001 XLM. The fee is calculated per operation by default using the current minimum base fee (100 stroops per operation).
Return values
int —The maximum fee in stroops
getMemo()
Returns the memo attached to this transaction
public
getMemo() : Memo
Return values
Memo —The transaction memo (defaults to Memo::none() if not set)
getOperations()
Returns all operations included in this transaction
public
getOperations() : array<string|int, AbstractOperation>
Operations are executed in the order they appear in this array.
Return values
array<string|int, AbstractOperation> —Array of operations to be executed
getPreconditions()
Returns the transaction preconditions if set
public
getPreconditions() : TransactionPreconditions|null
Return values
TransactionPreconditions|null —The preconditions or null if not set
getSequenceNumber()
Returns the sequence number for this transaction
public
getSequenceNumber() : BigInteger
The sequence number must be exactly one greater than the current sequence number of the source account.
Return values
BigInteger —The transaction sequence number
getSignatures()
Gets all signatures attached to this transaction
public
getSignatures() : array<string|int, XdrDecoratedSignature>
Return values
array<string|int, XdrDecoratedSignature> —Array of decorated signatures
getSorobanTransactionData()
Returns the Soroban transaction data if this is a smart contract transaction
public
getSorobanTransactionData() : XdrSorobanTransactionData|null
Return values
XdrSorobanTransactionData|null —Soroban-specific data or null for standard transactions
getSourceAccount()
Returns the source account for this transaction
public
getSourceAccount() : MuxedAccount
Return values
MuxedAccount —The transaction source account
getTimeBounds()
Returns the time bounds for this transaction if set
public
getTimeBounds() : TimeBounds|null
Time bounds restrict when a transaction can be successfully executed. Returns null if no time restrictions are set.
Return values
TimeBounds|null —The time bounds or null if not restricted
hash()
Calculates the hash of the transaction for signing
public
hash(Network $network) : string
Parameters
- $network : Network
-
The network for which to calculate the hash
Return values
string —The transaction hash
setFee()
Sets the maximum fee for this transaction in stroops
public
setFee(int $fee) : void
Parameters
- $fee : int
-
The maximum fee to pay in stroops
setSignatures()
Sets the signatures for this transaction
public
setSignatures(array<string|int, XdrDecoratedSignature> $signatures) : void
Parameters
- $signatures : array<string|int, XdrDecoratedSignature>
-
Array of decorated signatures
setSorobanAuth()
Sets authorization entries for Soroban smart contract invocations
public
setSorobanAuth([array<string|int, SorobanAuthorizationEntry>|null $auth = array() ]) : void
This method updates all InvokeHostFunctionOperation instances in the transaction with the provided authorization data.
Parameters
- $auth : array<string|int, SorobanAuthorizationEntry>|null = array()
-
Array of authorization entries or null/empty array to clear
setSorobanTransactionData()
Sets Soroban transaction data for smart contract transactions
public
setSorobanTransactionData(XdrSorobanTransactionData|null $sorobanTransactionData) : void
Parameters
- $sorobanTransactionData : XdrSorobanTransactionData|null
-
Soroban-specific transaction data
sign()
Signs the transaction with the provided keypair
public
sign(KeyPair $signer, Network $network) : void
Parameters
- $signer : KeyPair
-
The keypair used to sign the transaction (must have private key)
- $network : Network
-
The network for which this transaction is intended
Tags
signatureBase()
Generates the signature base for this transaction
public
signatureBase(Network $network) : string
The signature base is what gets signed by keypairs. It includes the network passphrase hash, envelope type, and transaction XDR.
Parameters
- $network : Network
-
The network this transaction is intended for
Return values
string —Raw bytes to be signed
toEnvelopeXdr()
Converts this transaction to a complete XDR transaction envelope
public
toEnvelopeXdr() : XdrTransactionEnvelope
The envelope includes the transaction data and all signatures.
Return values
XdrTransactionEnvelope —Complete transaction envelope ready for submission
toEnvelopeXdrBase64()
Converts the transaction to base64-encoded XDR envelope format
public
toEnvelopeXdrBase64() : string
Return values
string —Base64-encoded XDR transaction envelope
toXdr()
Converts this transaction to its XDR representation
public
toXdr() : XdrTransaction
Return values
XdrTransaction —XDR format of this transaction
toXdrBase64()
Converts this transaction to base64-encoded XDR
public
toXdrBase64() : string
Return values
string —Base64-encoded XDR representation