Struct TransactionBuilder

Source
pub struct TransactionBuilder {
    pub fee: u32,
    pub source_account: Account,
    pub operations: Vec<Operation>,
    pub memo: Memo,
    pub preconditions: Preconditions,
    pub env: Env,
}
Expand description

Builder for creating and configuring Stellar transactions.

TransactionBuilder provides an API for building Stellar transactions for Soroban operations. It handles sequence number retrieval, fee calculation, and transaction simulation to ensure transactions have the correct resources allocated for Soroban execution.

Fields§

§fee: u32

Transaction fee in stroops

§source_account: Account

Account that will be the source of the transaction

§operations: Vec<Operation>

List of operations to include in the transaction

§memo: Memo

Optional memo to attach to the transaction

§preconditions: Preconditions

Optional preconditions for transaction execution

§env: Env

Environment for network interaction

Implementations§

Source§

impl TransactionBuilder

Source

pub fn new(source_account: &Account, env: &Env) -> Self

Creates a new transaction builder for the specified account and environment.

The builder is initialized with default values:

  • Default transaction fee
  • Empty operations list
  • No memo
  • No preconditions
§Parameters
  • source_account - The account that will be the source of the transaction
  • env - The environment for network interaction
§Returns

A new TransactionBuilder instance

Source

pub fn set_env(self, env: Env) -> Self

Sets the environment for the transaction builder.

§Parameters
  • env - The new environment to use
§Returns

The updated TransactionBuilder

Source

pub fn add_operation(self, operation: Operation) -> Self

Adds an operation to the transaction.

https://developers.stellar.org/docs/learn/fundamentals/transactions/operations-and-transactions#operations

§Parameters
  • operation - The operation to add
§Returns

The updated TransactionBuilder

Source

pub fn set_memo(self, memo: Memo) -> Self

Sets the memo for the transaction.

Memos can be used to attach additional information to a transaction. They are not used by the protocol but can be used by applications. https://developers.stellar.org/docs/learn/encyclopedia/transactions-specialized/memos

§Parameters
  • memo - The memo to set
§Returns

The updated TransactionBuilder

Source

pub fn set_preconditions(self, preconditions: Preconditions) -> Self

Sets the preconditions for the transaction.

Preconditions specify requirements that must be met for a transaction to be valid, such as time bounds or ledger bounds. https://developers.stellar.org/docs/learn/fundamentals/transactions/operations-and-transactions#preconditions

§Parameters
  • preconditions - The preconditions to set
§Returns

The updated TransactionBuilder

Source

pub async fn build(self) -> Result<Transaction, SorobanHelperError>

Builds a transaction without simulation.

This method retrieves the source account’s current sequence number and constructs a transaction with the configured parameters.

§Returns

A transaction ready to be signed, or an error if the build fails

§Errors

Returns error if:

  • Operations cannot be converted to XDR
  • Sequence number cannot be retrieved
Source

pub async fn simulate_and_build( self, env: &Env, source_account: &Account, ) -> Result<Transaction, SorobanHelperError>

Builds a transaction with simulation to determine proper fees and resources.

This method:

  1. Builds a transaction with default fees
  2. Simulates the transaction to determine required resources
  3. Updates the transaction with the correct fees and resource data

This is the recommended way to build Soroban transactions, as it ensures they have sufficient fees and resources for execution.

§Parameters
  • env - The environment for transaction simulation
  • account - The account to use for signing the simulation transaction
§Returns

A transaction optimized for Soroban execution, or an error if the build fails

§Errors

Returns error if:

  • Transaction building fails
  • Transaction signing fails
  • Simulation fails
  • Fee calculation results in a value too large for u32

Trait Implementations§

Source§

impl Clone for TransactionBuilder

Source§

fn clone(&self) -> TransactionBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSend for T
where T: Send,