pub struct Client { /* private fields */ }Expand description
Client allows you to send typed RPC requests to a Solana cluster.
Implementations§
Source§impl Client
impl Client
Sourcepub fn anchor_client(&self) -> &AnchorClient
pub fn anchor_client(&self) -> &AnchorClient
Gets the internal Anchor client to call Anchor client’s methods directly.
Sourcepub fn program(&self, program_id: Pubkey) -> Program
pub fn program(&self, program_id: Pubkey) -> Program
Creates Program instance to communicate with the selected program.
Sourcepub async fn is_localnet_running(&self, retry: bool) -> bool
pub async fn is_localnet_running(&self, retry: bool) -> bool
Finds out if the Solana localnet is running.
Set retry to true when you want to wait for up to 15 seconds until
the localnet is running (until 30 retries with 500ms delays are performed).
Sourcepub async fn account_data<T>(&self, account: Pubkey) -> Result<T, Error>where
T: AccountDeserialize + Send + 'static,
pub async fn account_data<T>(&self, account: Pubkey) -> Result<T, Error>where
T: AccountDeserialize + Send + 'static,
Gets deserialized data from the chosen account serialized with Anchor
§Errors
It fails when:
- the account does not exist.
- the Solana cluster is not running.
- deserialization failed.
Sourcepub async fn account_data_bincode<T>(&self, account: Pubkey) -> Result<T, Error>where
T: DeserializeOwned + Send + 'static,
pub async fn account_data_bincode<T>(&self, account: Pubkey) -> Result<T, Error>where
T: DeserializeOwned + Send + 'static,
Gets deserialized data from the chosen account serialized with Bincode
§Errors
It fails when:
- the account does not exist.
- the Solana cluster is not running.
- deserialization failed.
Sourcepub async fn account_data_borsh<T>(&self, account: Pubkey) -> Result<T, Error>where
T: BorshDeserialize + Send + 'static,
pub async fn account_data_borsh<T>(&self, account: Pubkey) -> Result<T, Error>where
T: BorshDeserialize + Send + 'static,
Gets deserialized data from the chosen account serialized with Borsh
§Errors
It fails when:
- the account does not exist.
- the Solana cluster is not running.
- deserialization failed.
Sourcepub async fn send_instruction(
&self,
program: Pubkey,
instruction: impl InstructionData + Send + 'static,
accounts: impl ToAccountMetas + Send + 'static,
signers: impl IntoIterator<Item = Keypair> + Send + 'static,
) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
pub async fn send_instruction( &self, program: Pubkey, instruction: impl InstructionData + Send + 'static, accounts: impl ToAccountMetas + Send + 'static, signers: impl IntoIterator<Item = Keypair> + Send + 'static, ) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
Sends the Anchor instruction with associated accounts and signers.
§Example
use trdelnik_client::*;
pub async fn initialize(
client: &Client,
state: Pubkey,
user: Pubkey,
system_program: Pubkey,
signers: impl IntoIterator<Item = Keypair> + Send + 'static,
) -> Result<EncodedConfirmedTransaction, ClientError> {
Ok(client
.send_instruction(
PROGRAM_ID,
turnstile::instruction::Initialize {},
turnstile::accounts::Initialize {
state: a_state,
user: a_user,
system_program: a_system_program,
},
signers,
)
.await?)
}Sourcepub async fn send_transaction(
&self,
instructions: &[Instruction],
signers: impl IntoIterator<Item = &Keypair> + Send,
) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
pub async fn send_transaction( &self, instructions: &[Instruction], signers: impl IntoIterator<Item = &Keypair> + Send, ) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
Sends the transaction with associated instructions and signers.
§Example
#[throws]
pub async fn create_account(
&self,
keypair: &Keypair,
lamports: u64,
space: u64,
owner: &Pubkey,
) -> EncodedConfirmedTransaction {
self.send_transaction(
&[system_instruction::create_account(
&self.payer().pubkey(),
&keypair.pubkey(),
lamports,
space,
owner,
)],
[keypair],
)
.await?
}Sourcepub async fn airdrop(&self, address: Pubkey, lamports: u64) -> Result<(), Error>
pub async fn airdrop(&self, address: Pubkey, lamports: u64) -> Result<(), Error>
Airdrops lamports to the chosen account.
Sourcepub async fn get_balance(&mut self, address: Pubkey) -> Result<u64, Error>
pub async fn get_balance(&mut self, address: Pubkey) -> Result<u64, Error>
Get balance of an account
Sourcepub async fn get_token_balance(
&mut self,
address: Pubkey,
) -> Result<UiTokenAmount, Error>
pub async fn get_token_balance( &mut self, address: Pubkey, ) -> Result<UiTokenAmount, Error>
Get token balance of an token account
Sourcepub async fn deploy_by_name(
&self,
program_keypair: &Keypair,
program_name: &str,
) -> Result<(), Error>
pub async fn deploy_by_name( &self, program_keypair: &Keypair, program_name: &str, ) -> Result<(), Error>
Deploys a program based on it’s name. This function wraps boilerplate code required for the successful deployment of a program, i.e. SOLs airdrop etc.
§Arguments
program_keypair- Keypair used for the programprogram_name- Name of the program to be deployed
§Example:
Project structure
project/
- programs/
- awesome_contract/
- ...
- Cargo.toml
- turnstile/
- ...
- Cargo.toml
- ...
- Cargo.tomlCode
client.deploy_program(program_keypair(0), "awesome_contract");
client.deploy_program(program_keypair(1), "turnstile");Sourcepub async fn create_account(
&self,
keypair: &Keypair,
lamports: u64,
space: u64,
owner: &Pubkey,
) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
pub async fn create_account( &self, keypair: &Keypair, lamports: u64, space: u64, owner: &Pubkey, ) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
Creates accounts.
Sourcepub async fn create_account_rent_exempt(
&mut self,
keypair: &Keypair,
space: u64,
owner: &Pubkey,
) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
pub async fn create_account_rent_exempt( &mut self, keypair: &Keypair, space: u64, owner: &Pubkey, ) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
Creates rent exempt account.
Sourcepub async fn create_token_mint(
&self,
mint: &Keypair,
authority: Pubkey,
freeze_authority: Option<Pubkey>,
decimals: u8,
) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
pub async fn create_token_mint( &self, mint: &Keypair, authority: Pubkey, freeze_authority: Option<Pubkey>, decimals: u8, ) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
Executes a transaction constructing a token mint.
Sourcepub async fn mint_tokens(
&self,
mint: Pubkey,
authority: &Keypair,
account: Pubkey,
amount: u64,
) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
pub async fn mint_tokens( &self, mint: Pubkey, authority: &Keypair, account: Pubkey, amount: u64, ) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
Executes a transaction that mints tokens from a mint to an account belonging to that mint.
Sourcepub async fn create_token_account(
&self,
account: &Keypair,
mint: &Pubkey,
owner: &Pubkey,
) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
pub async fn create_token_account( &self, account: &Keypair, mint: &Pubkey, owner: &Pubkey, ) -> Result<EncodedConfirmedTransactionWithStatusMeta, Error>
Executes a transaction constructing a token account of the specified mint. The account needs to be empty and belong to system for this to work. Prefer to use create_associated_token_account if you don’t need the provided account to contain the token account.
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl !Send for Client
impl !Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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