Transaction class
Represents a transaction in the Stellar network.
A transaction is a grouping of operations that are executed atomically on the Stellar ledger. Transactions are the fundamental unit of change in Stellar - they contain one or more operations and must be signed by the source account(s) before submission to the network.
Transaction workflow:
- Build the transaction with operations using TransactionBuilder
- Sign the transaction with one or more keypairs using sign
- Convert to XDR format using toEnvelopeXdrBase64
- Submit the XDR to the network via Horizon or Soroban RPC
Example:
// Load the source account from the network
Account sourceAccount = await sdk.accounts.account(sourceKeyPair.accountId);
// Build a transaction with a payment operation
Transaction transaction = TransactionBuilder(sourceAccount)
.addOperation(
PaymentOperationBuilder(
destinationAccountId,
Asset.native(),
"100.50"
).build()
)
.addMemo(Memo.text("Payment memo"))
.build();
// Sign the transaction
transaction.sign(sourceKeyPair, Network.TESTNET);
// Submit to the network
SubmitTransactionResponse response = await sdk.submitTransaction(transaction);
Security considerations:
- Always verify the network passphrase matches your intended network
- Review all operations before signing
- Keep private keys secure and never expose them
- Validate transaction results before considering operations complete
See also:
- TransactionBuilder for constructing transactions
- Operation for available operation types
- Network for network passphrases
- Stellar developer docs
- Inheritance
-
- Object
- AbstractTransaction
- Transaction
Constructors
-
Transaction(MuxedAccount _mSourceAccount, int _mFee, BigInt _mSequenceNumber, List<
Operation> _mOperations, Memo? memo, TransactionPreconditions? preconditions, {XdrSorobanTransactionData? sorobanTransactionData}) - Creates a new Transaction.
Properties
- fee ↔ int
-
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- memo → Memo?
-
no setter
-
operations
→ List<
Operation> -
Returns the list of operations in this transaction.
no setter
- preconditions → TransactionPreconditions?
-
Return transaction preconditions as specified by CAP-21 and CAP-40
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sequenceNumber → BigInt
-
no setter
-
signatures
↔ List<
XdrDecoratedSignature> -
Gets the list of signatures attached to this transaction.
getter/setter pairinherited
- sorobanTransactionData ↔ XdrSorobanTransactionData?
-
getter/setter pair
- sourceAccount → MuxedAccount
-
no setter
Methods
-
addResourceFee(
int resourceFee) → dynamic - Adds additional resource fee to the transaction fee.
-
hash(
Network network) → Uint8List -
Returns the transaction hash of this transaction.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setSorobanAuth(
List< SorobanAuthorizationEntry> ? auth) → dynamic - Sets Soroban authorization entries for invoke contract operations.
-
sign(
KeyPair signer, Network network) → void -
Signs the transaction with the given keypair for a specific network.
inherited
-
signatureBase(
Network network) → Uint8List -
Returns signature base of this transaction.
override
-
signHash(
Uint8List preimage) → void -
Adds a sha256Hash signature to this transaction by revealing
preimage.inherited -
toEnvelopeXdr(
) → XdrTransactionEnvelope -
Generates a TransactionEnvelope XDR object for this transaction.
This transaction needs to have at least one signature.
override
-
toEnvelopeXdrBase64(
) → String -
Returns a base64-encoded TransactionEnvelope XDR object of this transaction.
This transaction needs to have at least one signature.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
toV0Xdr(
) → XdrTransactionV0 - Generates a V0 Transaction XDR object for this transaction.
-
toXdr(
) → XdrTransaction - Converts this transaction to its XDR representation.
-
toXdrBase64(
) → String - Converts this transaction to base64-encoded XDR format.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
builder(
TransactionBuilderAccount sourceAccount) → TransactionBuilder - Creates a new transaction builder for the specified source account.
-
fromV0EnvelopeXdr(
XdrTransactionV0Envelope envelope) → Transaction -
Creates a Transaction instance from a XdrTransactionV0Envelope
envelope. -
fromV1EnvelopeXdr(
XdrTransactionV1Envelope envelope) → Transaction -
Creates a Transaction instance from a XdrTransactionV1Envelope
envelope.