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
impl TransactionBuilder
Sourcepub fn new(source_account: &Account, env: &Env) -> Self
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 transactionenv
- The environment for network interaction
§Returns
A new TransactionBuilder instance
Sourcepub fn add_operation(self, operation: Operation) -> Self
pub fn add_operation(self, operation: Operation) -> Self
Sourcepub fn set_memo(self, memo: Memo) -> Self
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
Sourcepub fn set_preconditions(self, preconditions: Preconditions) -> Self
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
Sourcepub async fn build(self) -> Result<Transaction, SorobanHelperError>
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
Sourcepub async fn simulate_and_build(
self,
env: &Env,
source_account: &Account,
) -> Result<Transaction, SorobanHelperError>
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:
- Builds a transaction with default fees
- Simulates the transaction to determine required resources
- 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 simulationaccount
- 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
impl Clone for TransactionBuilder
Source§fn clone(&self) -> TransactionBuilder
fn clone(&self) -> TransactionBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for TransactionBuilder
impl !RefUnwindSafe for TransactionBuilder
impl Send for TransactionBuilder
impl Sync for TransactionBuilder
impl Unpin for TransactionBuilder
impl !UnwindSafe for TransactionBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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