Transaction

Represents a transaction in the Stellar network.

A transaction is a grouping of operations that are executed together atomically. All operations must succeed for the transaction to succeed. If any operation fails, all effects are rolled back.

Transaction Structure

A transaction consists of:

  • Source Account: The account that originates the transaction and pays the fee

  • Fee: Total fee in stroops (baseFee * operations.size)

  • Sequence Number: Must be exactly sourceAccount.sequence + 1

  • Operations: List of 1-100 operations to execute

  • Memo: Optional memo (up to 28 bytes for text memos)

  • Preconditions: Optional time bounds, ledger bounds, etc.

  • Signatures: List of signatures authorizing the transaction

Building Transactions

Use TransactionBuilder to construct transactions:

val sourceAccount = Account("GABC...", 1234567890)
val transaction = TransactionBuilder(sourceAccount, Network.TESTNET)
.addOperation(
PaymentOperation(
destination = "GDEF...",
asset = AssetTypeNative,
amount = "10.0"
)
)
.addMemo(MemoText("Payment for services"))
.setTimeout(300) // 5 minutes
.setBaseFee(100)
.build()

// Sign with source account keypair
transaction.sign(sourceKeypair)

// Submit to Horizon
val response = horizonServer.submitTransaction(transaction)

Fee Calculation

The transaction fee is calculated as: baseFee * operations.size

The minimum base fee is 100 stroops (0.00001 XLM), so:

  • 1 operation: 100 stroops = 0.00001 XLM

  • 10 operations: 1,000 stroops = 0.0001 XLM

  • 100 operations: 10,000 stroops = 0.001 XLM

Sequence Numbers

Each account has a sequence number that must be incremented with each transaction. The transaction's sequence number must be exactly sourceAccount.sequence + 1. After successful execution, the account's sequence number becomes the transaction's sequence number.

See also

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val fee: Long

Total transaction fee in stroops

Link copied to clipboard
val memo: Memo

Transaction memo (default MemoNone)

Link copied to clipboard

The network this transaction is for

Link copied to clipboard

List of operations (1-100)

Link copied to clipboard

Transaction preconditions (time/ledger bounds, etc.)

Link copied to clipboard

The sequence number for this transaction

Link copied to clipboard

List of signatures attached to this transaction.

Link copied to clipboard

Soroban transaction data for smart contract operations (optional)

Link copied to clipboard

The source account for this transaction (G... or M... address)

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard

Returns the time bounds defined for the transaction.

Link copied to clipboard
suspend fun hash(): ByteArray

Returns the transaction hash (SHA-256 of signature base).

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
suspend fun hashHex(): String

Returns the transaction hash as a lowercase hexadecimal string.

Link copied to clipboard

Returns true if this is a Soroban transaction.

Link copied to clipboard
suspend fun sign(signer: KeyPair)

Adds a signature by signing the transaction hash with the provided keypair.

Link copied to clipboard
open suspend override fun signatureBase(): ByteArray

Returns the signature base - the data that must be signed.

Link copied to clipboard
suspend fun signHashX(preimage: ByteArray)

Adds a hash(x) signature by revealing the preimage.

Link copied to clipboard

Converts this transaction to its XDR envelope representation.

Link copied to clipboard

Returns base64-encoded TransactionEnvelope XDR.

Link copied to clipboard
open override fun toString(): String