Class TransactionBuilder

java.lang.Object
org.stellar.sdk.TransactionBuilder

public class TransactionBuilder extends Object
Builds a new Transaction object.
  • Constructor Details

    • TransactionBuilder

      public TransactionBuilder(@NonNull @NonNull TransactionBuilderAccount sourceAccount, @NonNull @NonNull Network network)
      Construct a new transaction builder.
      Parameters:
      sourceAccount - the source account for this transaction. This account is the account who will use a sequence number. When build() is called, the account object's sequence number will be incremented.
      network - the testnet or pubnet network to use
  • Method Details

    • getOperationsCount

      public int getOperationsCount()
    • addOperation

      public TransactionBuilder addOperation(@NonNull @NonNull Operation operation)
      Adds a new operation to this transaction.
      Parameters:
      operation - the operation to add
      Returns:
      Builder object so you can chain methods.
      See Also:
    • addOperations

      public TransactionBuilder addOperations(@NonNull @NonNull Collection<Operation> operations)
      Adds operation to this transaction.
      Parameters:
      operations - list of operations
      Returns:
      Builder object so you can chain methods.
      See Also:
    • addPreconditions

      public TransactionBuilder addPreconditions(@NonNull @NonNull TransactionPreconditions preconditions)
      Adds preconditions. For details of all preconditions on transaction refer to CAP-21
      Parameters:
      preconditions - the tx PreConditions
      Returns:
      updated Builder object
    • addMemo

      public TransactionBuilder addMemo(@NonNull @NonNull Memo memo)
      Adds a memo to this transaction.
      Parameters:
      memo - memo to add
      Returns:
      Builder object so you can chain methods.
      See Also:
    • setTimeout

      public TransactionBuilder setTimeout(BigInteger timeout)
      Because of the distributed nature of the Stellar network it is possible that the status of your transaction will be determined after a long time if the network is highly congested. If you want to be sure to receive the status of the transaction within a given period you should set the TimeBounds with maxTime on the transaction (this is what setTimeout does internally; if there's minTime set but no maxTime it will be added). Call to Builder.setTimeout is required if Transaction does not have max_time set. If you don't want to set timeout, use TIMEOUT_INFINITE. In general, you should set TIMEOUT_INFINITE only in smart contracts. Please note that Horizon may still return 504 Gateway Timeout error, even for short timeouts. In such case you need to resubmit the same transaction again without making any changes to receive a status. This method is using the machine system time (UTC), make sure it is set correctly.
      Parameters:
      timeout - Timeout in seconds.
      Returns:
      updated Builder
      See Also:
    • setTimeout

      public TransactionBuilder setTimeout(long timeout)
      An alias for setTimeout(BigInteger) with timeout in seconds.
      Parameters:
      timeout - Timeout in seconds.
      Returns:
      updated Builder
    • setBaseFee

      public TransactionBuilder setBaseFee(long baseFee)
    • build

      public Transaction build()
      Builds a transaction and increments the sequence number on the source account after transaction is constructed.
    • setSorobanData

      public TransactionBuilder setSorobanData(SorobanTransactionData sorobanData)
      Sets the transaction's internal Soroban transaction data (resources, footprint, etc.).

      For non-contract(non-Soroban) transactions, this setting has no effect. In the case of Soroban transactions, this is either an instance of SorobanTransactionData or a base64-encoded string of said structure. This is usually obtained from the simulation response based on a transaction with a Soroban operation (e.g. InvokeHostFunctionOperation, providing necessary resource and storage footprint estimations for contract invocation.

      Parameters:
      sorobanData - Soroban data to set
      Returns:
      Builder object so you can chain methods.
    • setSorobanData

      public TransactionBuilder setSorobanData(String sorobanData)
      Sets the transaction's internal Soroban transaction data (resources, footprint, etc.).

      For non-contract(non-Soroban) transactions, this setting has no effect. In the case of Soroban transactions, this is either an instance of SorobanTransactionData or a base64-encoded string of said structure. This is usually obtained from the simulation response based on a transaction with a Soroban operation (e.g. InvokeHostFunctionOperation, providing necessary resource and storage footprint estimations for contract invocation.

      Parameters:
      sorobanData - Soroban data to set
      Returns:
      Builder object so you can chain methods.