TransactionBuilder

TransactionBuilder

Transaction builder helps constructs a new Transaction using the given Account as the transaction's "source account". The transaction will use the current sequence number of the given account as its sequence number and increment the given account's sequence number by one. The given source account must include a private key for signing the transaction or an error will be thrown.

Operations can be added to the transaction via their corresponding builder methods, and each returns the TransactionBuilder object so they can be chained together. After adding the desired operations, call the build() method on the TransactionBuilder to return a fully constructed Transaction that can be signed. The returned transaction will contain the sequence number of the source account and include the signature from the source account.

The following code example creates a new transaction with Operation.createAccount and Operation.payment operations. The Transaction's source account first funds destinationA, then sends a payment to destinationB. The built transaction is then signed by sourceKeypair.

var transaction = new TransactionBuilder(source)
 .addOperation(Operation.createAccount({
        destination: destinationA,
        startingBalance: "20"
    }) // <- funds and creates destinationA
    .addOperation(Operation.payment({
        destination: destinationB,
        amount: "100"
        asset: Asset.native()
    }) // <- sends 100 XLM to destinationB
  .build();

transaction.sign(sourceKeypair);

Constructor

new TransactionBuilder(sourceAccount, optsopt)

Source:
Parameters:
Name Type Attributes Description
sourceAccount Account

The source account for this transaction.

opts object <optional>
Name Type Attributes Description
fee number <optional>

The max fee willing to pay per operation in this transaction (in stroops).

timebounds object <optional>

The timebounds for the validity of this transaction.

Name Type Attributes Description
minTime number | string <optional>

64 bit unix timestamp

maxTime number | string <optional>

64 bit unix timestamp

memo Memo <optional>

The memo for the transaction

Methods

addMemo(memo) → {TransactionBuilder}

Adds a memo to the transaction.

Source:
Parameters:
Name Type Description
memo Memo

Memo object

Returns:
Type:
TransactionBuilder

addOperation(operation) → {TransactionBuilder}

Adds an operation to the transaction.

Source:
Parameters:
Name Type Description
operation xdr.Operation

The xdr operation object, use Operation static methods.

Returns:
Type:
TransactionBuilder

build() → {Transaction}

This will build the transaction. It will also increment the source account's sequence number by 1.

Source:
Returns:
Type:
Transaction

This method will return the built Transaction.