pub struct TransactionBuilder { /* private fields */ }Expand description
A builder for constructing transactions.
§Example
use aptos_sdk::transaction::{TransactionBuilder, EntryFunction};
use aptos_sdk::types::{AccountAddress, ChainId};
let payload = EntryFunction::apt_transfer(
AccountAddress::from_hex("0x123").unwrap(),
1000,
).unwrap();
let txn = TransactionBuilder::new()
.sender(AccountAddress::ONE)
.sequence_number(0)
.payload(payload.into())
.chain_id(ChainId::testnet())
.build()
.unwrap();Implementations§
Source§impl TransactionBuilder
impl TransactionBuilder
Sourcepub fn sender(self, sender: AccountAddress) -> Self
pub fn sender(self, sender: AccountAddress) -> Self
Sets the sender address.
Sourcepub fn sequence_number(self, sequence_number: u64) -> Self
pub fn sequence_number(self, sequence_number: u64) -> Self
Sets the sequence number.
Sourcepub fn payload(self, payload: TransactionPayload) -> Self
pub fn payload(self, payload: TransactionPayload) -> Self
Sets the transaction payload.
Sourcepub fn max_gas_amount(self, max_gas_amount: u64) -> Self
pub fn max_gas_amount(self, max_gas_amount: u64) -> Self
Sets the maximum gas amount.
Sourcepub fn gas_unit_price(self, gas_unit_price: u64) -> Self
pub fn gas_unit_price(self, gas_unit_price: u64) -> Self
Sets the gas unit price in octas.
Sourcepub fn expiration_timestamp_secs(self, expiration_timestamp_secs: u64) -> Self
pub fn expiration_timestamp_secs(self, expiration_timestamp_secs: u64) -> Self
Sets the expiration timestamp in seconds since Unix epoch.
Sourcepub fn expiration_from_now(self, seconds: u64) -> Self
pub fn expiration_from_now(self, seconds: u64) -> Self
Sets the expiration time relative to now.
Uses saturating arithmetic to handle edge cases like system time going backwards.
Sourcepub fn build(self) -> AptosResult<RawTransaction>
pub fn build(self) -> AptosResult<RawTransaction>
Builds the raw transaction.
§Errors
Returns an error if any required field is missing:
senderis requiredsequence_numberis requiredpayloadis requiredchain_idis required
Sourcepub fn build_and_sign<A: Account>(
self,
account: &A,
) -> AptosResult<SignedTransaction>
Available on crate feature ed25519 only.
pub fn build_and_sign<A: Account>( self, account: &A, ) -> AptosResult<SignedTransaction>
ed25519 only.Builds and signs the transaction with the given account.
§Errors
Returns an error if the transaction cannot be built or signed.
Trait Implementations§
Source§impl Clone for TransactionBuilder
impl Clone for TransactionBuilder
Source§fn clone(&self) -> TransactionBuilder
fn clone(&self) -> TransactionBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TransactionBuilder
impl Debug for TransactionBuilder
Auto 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
Mutably borrows from an owned value. Read more