TransactionBuilder

class TransactionBuilder(val sourceAccount: TransactionBuilderAccount, val network: Network)

Builds a new Transaction following the builder pattern.

TransactionBuilder provides a fluent API for constructing Stellar transactions with all necessary parameters and validations.

Usage

val sourceAccount = Account("GABC...", 1234567890)

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

transaction.sign(keypair)

Fee Calculation

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

You must set the base fee explicitly using setBaseFee before building.

Sequence Number Management

The builder automatically increments the source account's sequence number when build is called. This ensures the transaction has the correct sequence number (account.sequence + 1).

See also

Constructors

Link copied to clipboard
constructor(sourceAccount: TransactionBuilderAccount, network: Network)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The network this transaction is for (TESTNET, PUBLIC, etc.)

Link copied to clipboard

The source account for this transaction

Functions

Link copied to clipboard

Adds a memo to this transaction.

Link copied to clipboard

Adds an operation to this transaction.

Link copied to clipboard

Adds multiple operations to this transaction.

Link copied to clipboard

Adds preconditions to this transaction.

Link copied to clipboard

Adds time bounds to this transaction.

Link copied to clipboard

Builds the transaction and increments the source account's sequence number.

Link copied to clipboard

Returns the number of operations currently added to this transaction.

Link copied to clipboard

Sets the base fee per operation for this transaction.

Link copied to clipboard

Sets Soroban transaction data for smart contract operations.

Link copied to clipboard

Sets the transaction timeout in seconds from now.

Sets the transaction timeout using Kotlin Duration from now.