pub struct SponsoredTransactionBuilder { /* private fields */ }Expand description
A builder for constructing sponsored (fee payer) transactions.
This provides a fluent API for creating transactions where a fee payer account pays the gas fees on behalf of the sender.
§Example
use aptos_sdk::transaction::{SponsoredTransactionBuilder, EntryFunction};
// Build the fee payer transaction structure
let fee_payer_txn = SponsoredTransactionBuilder::new()
.sender(user_account.address())
.sequence_number(0)
.fee_payer(sponsor_account.address())
.payload(payload)
.chain_id(ChainId::testnet())
.build()?;
// Then sign it
let signed = sign_sponsored_transaction(
&fee_payer_txn,
&user_account,
&[], // no secondary signers
&sponsor_account,
)?;Implementations§
Source§impl SponsoredTransactionBuilder
impl SponsoredTransactionBuilder
Sourcepub fn sender(self, address: AccountAddress) -> Self
pub fn sender(self, address: 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 sender’s sequence number.
Sourcepub fn secondary_signer(self, address: AccountAddress) -> Self
pub fn secondary_signer(self, address: AccountAddress) -> Self
Adds a secondary signer address to the transaction.
Secondary signers are additional accounts that must sign the transaction. This is useful for multi-party transactions.
Sourcepub fn secondary_signers(self, addresses: &[AccountAddress]) -> Self
pub fn secondary_signers(self, addresses: &[AccountAddress]) -> Self
Adds multiple secondary signer addresses to the transaction.
Sourcepub fn fee_payer(self, address: AccountAddress) -> Self
pub fn fee_payer(self, address: AccountAddress) -> Self
Sets the fee payer address.
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.
Sourcepub fn build(self) -> AptosResult<FeePayerRawTransaction>
pub fn build(self) -> AptosResult<FeePayerRawTransaction>
Builds the raw fee payer transaction (unsigned).
This returns a FeePayerRawTransaction that can be signed later
by the sender, secondary signers, and fee payer.
§Errors
Returns an error if sender, sequence_number, payload, chain_id, or fee_payer is not set.
Sourcepub fn build_and_sign<S, F>(
self,
sender: &S,
secondary_signers: &[&dyn Account],
fee_payer: &F,
) -> AptosResult<SignedTransaction>
pub fn build_and_sign<S, F>( self, sender: &S, secondary_signers: &[&dyn Account], fee_payer: &F, ) -> AptosResult<SignedTransaction>
Builds and signs the transaction with all provided accounts.
This is a convenience method that builds the transaction and signs it in one step.
§Example
let signed = SponsoredTransactionBuilder::new()
.sender(user.address())
.sequence_number(0)
.fee_payer(sponsor.address())
.payload(payload)
.chain_id(ChainId::testnet())
.build_and_sign(&user, &[], &sponsor)?;§Errors
Returns an error if building the transaction fails or if any signer fails to sign.
Trait Implementations§
Source§impl Clone for SponsoredTransactionBuilder
impl Clone for SponsoredTransactionBuilder
Source§fn clone(&self) -> SponsoredTransactionBuilder
fn clone(&self) -> SponsoredTransactionBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more