pub struct RequestBuilder<'a, C, S: 'a> { /* private fields */ }Expand description
RequestBuilder provides a builder interface to create and send
transactions to a cluster.
Implementations§
Source§impl<'a, C: Deref<Target = impl Signer> + Clone> RequestBuilder<'a, C, Box<dyn Signer + 'a>>
impl<'a, C: Deref<Target = impl Signer> + Clone> RequestBuilder<'a, C, Box<dyn Signer + 'a>>
pub fn from( program_id: Pubkey, cluster: &str, payer: C, options: Option<CommitmentConfig>, handle: &'a Handle, rpc_client: &'a AsyncRpcClient, ) -> Self
async only.pub fn signer<T: Signer + 'a>(self, signer: T) -> Self
async only.Sourcepub fn signed_transaction(&self) -> Result<Transaction, ClientError>
Available on non-crate feature async only.
pub fn signed_transaction(&self) -> Result<Transaction, ClientError>
async only.Build and sign a transaction.
Note: This will use a transaction with the legacy transaction format. If you’d like to use
a different transaction format, use [signed_transaction_versioned].
Sourcepub fn signed_transaction_versioned(
&self,
version: TxVersion<'_>,
) -> Result<VersionedTransaction, ClientError>
Available on non-crate feature async only.
pub fn signed_transaction_versioned( &self, version: TxVersion<'_>, ) -> Result<VersionedTransaction, ClientError>
async only.Sign and return a transaction with the specified version.
§Arguments
version- The transaction version to use (TxVersion::LegacyorTxVersion::V0).
§Example
use anchor_client::{Client, Cluster, TxVersion};
use anchor_lang::prelude::Pubkey;
use solana_signer::null_signer::NullSigner;
use solana_message::AddressLookupTableAccount;
let payer = NullSigner::new(&Pubkey::default());
let client = Client::new(Cluster::Localnet, std::rc::Rc::new(payer));
let program = client.program(Pubkey::default()).unwrap();
let lookup_table = AddressLookupTableAccount { key: Pubkey::default(), addresses: vec![] };
let request = program.request();
// Legacy transaction
let tx = request.signed_transaction_versioned(TxVersion::Legacy).unwrap();
// V0 transaction
let tx = request.signed_transaction_versioned(TxVersion::V0(&[lookup_table])).unwrap();Sourcepub fn send(&self) -> Result<Signature, ClientError>
Available on non-crate feature async only.
pub fn send(&self) -> Result<Signature, ClientError>
async only.Send a transaction.
Note: This will use a transaction with the legacy transaction format. If you’d like to use
a different transaction format, use [send_versioned].
Sourcepub fn send_versioned(
&self,
version: TxVersion<'_>,
) -> Result<Signature, ClientError>
Available on non-crate feature async only.
pub fn send_versioned( &self, version: TxVersion<'_>, ) -> Result<Signature, ClientError>
async only.Send a transaction with the specified version.
§Arguments
version- The transaction version to use (TxVersion::LegacyorTxVersion::V0).
§Example
use anchor_client::{Client, Cluster, TxVersion};
use anchor_lang::prelude::Pubkey;
use solana_signer::null_signer::NullSigner;
use solana_message::AddressLookupTableAccount;
let payer = NullSigner::new(&Pubkey::default());
let client = Client::new(Cluster::Localnet, std::rc::Rc::new(payer));
let program = client.program(Pubkey::default()).unwrap();
let lookup_table = AddressLookupTableAccount { key: Pubkey::default(), addresses: vec![] };
let request = program.request();
// Legacy transaction
let sig = request.send_versioned(TxVersion::Legacy).unwrap();
// V0 transaction with lookup tables
let sig = request.send_versioned(TxVersion::V0(&[lookup_table])).unwrap();Sourcepub fn send_with_spinner_and_config(
&self,
config: RpcSendTransactionConfig,
) -> Result<Signature, ClientError>
Available on non-crate feature async only.
pub fn send_with_spinner_and_config( &self, config: RpcSendTransactionConfig, ) -> Result<Signature, ClientError>
async only.Send a transaction with spinner and config.
Note: This will use a transaction with the legacy transaction format. If you’d like to use
a different transaction format, use [send_with_spinner_and_config_versioned].
Sourcepub fn send_with_spinner_and_config_versioned(
&self,
version: TxVersion<'_>,
config: RpcSendTransactionConfig,
) -> Result<Signature, ClientError>
Available on non-crate feature async only.
pub fn send_with_spinner_and_config_versioned( &self, version: TxVersion<'_>, config: RpcSendTransactionConfig, ) -> Result<Signature, ClientError>
async only.Send a transaction with the specified version, spinner and config.
§Arguments
version- The transaction version to use (TxVersion::LegacyorTxVersion::V0).config- RPC send transaction configuration.
Source§impl<C: Deref<Target = impl Signer> + Clone, S: AsSigner> RequestBuilder<'_, C, S>
impl<C: Deref<Target = impl Signer> + Clone, S: AsSigner> RequestBuilder<'_, C, S>
pub fn payer(self, payer: C) -> Self
pub fn cluster(self, url: &str) -> Self
pub fn instruction(self, ix: Instruction) -> Self
pub fn program(self, program_id: Pubkey) -> Self
Sourcepub fn accounts(self, accounts: impl ToAccountMetas) -> Self
pub fn accounts(self, accounts: impl ToAccountMetas) -> Self
Set the accounts to pass to the instruction.
accounts argument can be:
- Any type that implements
ToAccountMetastrait - A vector of
AccountMetas (for remaining accounts)
Note that the given accounts are appended to the previous list of accounts instead of overriding the existing ones (if any).
§Example
program
.request()
// Regular accounts
.accounts(accounts::Initialize {
my_account: my_account_kp.pubkey(),
payer: program.payer(),
system_program: system_program::ID,
})
// Remaining accounts
.accounts(vec![AccountMeta {
pubkey: remaining,
is_signer: true,
is_writable: true,
}])
.args(instruction::Initialize { field: 42 })
.send()?;pub fn options(self, options: CommitmentConfig) -> Self
pub fn args(self, args: impl InstructionData) -> Self
pub fn instructions(&self) -> Vec<Instruction>
Sourcepub fn transaction(&self) -> Transaction
pub fn transaction(&self) -> Transaction
Build the request into a transaction.
Note: This will build a transaction with the legacy transaction format. If you’d like to use
a different transaction format, use [transaction_versioned].
Sourcepub fn transaction_versioned(
&self,
version: TxVersion<'_>,
recent_blockhash: Hash,
) -> Result<VersionedTransaction, ClientError>
pub fn transaction_versioned( &self, version: TxVersion<'_>, recent_blockhash: Hash, ) -> Result<VersionedTransaction, ClientError>
Build an unsigned transaction.
§Arguments
version- The transaction version to use (TxVersion::LegacyorTxVersion::V0).recent_blockhash- A recent blockhash to include in the transaction message.
§Example
use anchor_client::{Client, Cluster, TxVersion};
use anchor_lang::prelude::Pubkey;
use solana_signer::null_signer::NullSigner;
use solana_message::AddressLookupTableAccount;
use solana_message::Hash;
let payer = NullSigner::new(&Pubkey::default());
let client = Client::new(Cluster::Localnet, std::rc::Rc::new(payer));
let program = client.program(Pubkey::default()).unwrap();
// Dummy blockhash
let blockhash = Hash::from([0; 32]);
let lookup_table = AddressLookupTableAccount { key: Pubkey::default(), addresses: vec![] };
let request = program.request();
// Legacy transaction
let tx = request.transaction_versioned(TxVersion::Legacy, blockhash).unwrap();
// V0 transaction with address lookup tables
let tx = request.transaction_versioned(TxVersion::V0(&[lookup_table]), blockhash).unwrap();
// V0 transaction without lookup tables
let tx = request.transaction_versioned(TxVersion::V0(&[]), blockhash).unwrap();Auto Trait Implementations§
impl<'a, C, S> !RefUnwindSafe for RequestBuilder<'a, C, S>
impl<'a, C, S> !UnwindSafe for RequestBuilder<'a, C, S>
impl<'a, C, S> Freeze for RequestBuilder<'a, C, S>where
C: Freeze,
impl<'a, C, S> Send for RequestBuilder<'a, C, S>
impl<'a, C, S> Sync for RequestBuilder<'a, C, S>
impl<'a, C, S> Unpin for RequestBuilder<'a, C, S>
impl<'a, C, S> UnsafeUnpin for RequestBuilder<'a, C, S>where
C: UnsafeUnpin,
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> 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