pub struct TransactionBuilder { /* private fields */ }
Expand description

Represents a transaction object used for building Solana transactions.

The TransactionBuilder struct provides methods for constructing and manipulating Solana transactions. It allows setting the payer, adding instructions, signers, and other transaction parameters. The transaction can be converted to a legacy transaction format or executed directly using the Solana RPC client.

§Examples

Creating a new transaction object with a payer:

use solana_sdk::pubkey::Pubkey;
use solana_sdk::instruction::Instruction;
use std::sync::Arc;

let payer = Pubkey::new_unique();
let transaction = TransactionBuilder::new(payer);

Adding an instruction to the transaction:

use solana_sdk::pubkey::Pubkey;
use solana_sdk::instruction::Instruction;
use std::sync::Arc;

let payer = Pubkey::new_unique();
let instruction = Instruction::new_with_bincode(program_id, data);
let transaction = TransactionBuilder::new(payer)
    .add_ix(instruction);

Converting the transaction object to a legacy transaction:

use solana_sdk::pubkey::Pubkey;
use solana_sdk::instruction::Instruction;
use std::sync::Arc;

let payer = Pubkey::new_unique();
let instruction = Instruction::new_with_bincode(program_id, data);
let transaction = TransactionBuilder::new(payer)
    .add_ix(instruction)
    .to_legacy_tx();

Implementations§

source§

impl TransactionBuilder

source

pub fn new(payer: Pubkey) -> Self

source

pub fn new_with_payer(payer: Arc<dyn AsSigner>) -> Self

source

pub fn new_with_ixs( payer: Pubkey, ixs: impl IntoIterator<Item = Instruction> ) -> Self

source

pub fn new_with_payer_and_ixs( payer: Arc<dyn AsSigner>, ixs: impl IntoIterator<Item = Instruction> ) -> Self

source

pub fn set_compute_units(self, compute_units: u32) -> Self

source

pub fn set_priority_fees(self, priority_fees: u64) -> Self

source

pub fn add_ix(self, ix: Instruction) -> Self

source

pub fn has_signer(&self, signer: Pubkey) -> bool

source

pub fn has_payer(&self) -> bool

source

pub fn add_signer(self, signer: Arc<dyn AsSigner>) -> TransactionBuilder

source

pub fn add_signers(self, signers: Vec<Arc<dyn AsSigner>>) -> TransactionBuilder

source

pub fn set_recent_blockhash(self, blockhash: Hash) -> Self

source

pub fn set_min_context_slot(self, min_context_slot: u64) -> Self

source

pub fn add_address_lookup_account( self, address_lookup_table: AddressLookupTableAccount ) -> Self

source

pub fn add_address_lookup_accounts( self, address_lookup_tables: &mut Vec<AddressLookupTableAccount> ) -> Self

source

pub async fn add_address_lookup_table( self, rpc: &RpcClient, address_lookup_table_pubkey: Pubkey ) -> Self

source

pub async fn add_address_lookup_tables( self, rpc: &RpcClient, address_lookup_table_pubkeys: Vec<Pubkey> ) -> Self

source

pub fn payer(&self) -> Pubkey

source

pub fn required_signers(&self) -> Vec<Pubkey>

Return a vec of all of the required signers for the transaction.

source

pub fn signers(&self) -> Result<Vec<&dyn Signer>, SbError>

Returns the stored signers for the transaction, removing any un-needed signers using the provided ixn’s AccountMeta’s.

source

pub fn ixs(&self) -> Result<Vec<Instruction>, SbError>

source

pub fn build_legacy_tx( payer: Pubkey, ixs: Vec<Instruction>, signers: Vec<&dyn Signer>, recent_blockhash: Hash ) -> Result<Transaction, SbError>

source

pub fn to_legacy_tx(&self) -> Result<Transaction, SbError>

source

pub fn to_legacy_tx_with_payer<T: AsSigner + Send + Sync>( &self, payer: T ) -> Result<Transaction, SbError>

source

pub fn to_legacy_tx_with_payer_and_blockhash<T: AsSigner + Send + Sync>( &self, payer: T, recent_blockhash: Option<Hash> ) -> Result<Transaction, SbError>

source

pub fn to_legacy_tx_with_blockhash( &self, recent_blockhash: Option<Hash> ) -> Result<Transaction, SbError>

source

pub async fn fetch_address_lookup_account( rpc: &RpcClient, address_lookup_table_pubkey: Pubkey ) -> Result<AddressLookupTableAccount, SbError>

source

pub async fn fetch_multiple_address_lookup_accounts( rpc: &RpcClient, address_lookup_pubkeys: Vec<Pubkey> ) -> Result<Vec<AddressLookupTableAccount>, SbError>

source

pub fn build_v0_tx( payer: Pubkey, ixs: Vec<Instruction>, signers: Vec<&dyn Signer>, address_lookup_accounts: Vec<AddressLookupTableAccount>, recent_blockhash: Hash ) -> Result<VersionedTransaction, SbError>

source

pub fn to_v0_tx(&self) -> Result<VersionedTransaction, SbError>

source

pub fn to_v0_tx_with_payer<T: AsSigner + Send + Sync>( &self, payer: T ) -> Result<VersionedTransaction, SbError>

Trait Implementations§

source§

impl Clone for TransactionBuilder

source§

fn clone(&self) -> TransactionBuilder

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Default for TransactionBuilder

source§

fn default() -> TransactionBuilder

Returns the “default value” for a type. Read more
source§

impl TryFrom<TransactionBuilder> for Transaction

§

type Error = SbError

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

fn try_from(builder: TransactionBuilder) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<TransactionBuilder> for VersionedTransaction

§

type Error = SbError

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

fn try_from(builder: TransactionBuilder) -> Result<Self, Self::Error>

Performs the conversion.

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

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> 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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.
§

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

§

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