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

Client allows you to send typed RPC requests to a Solana cluster.

Implementations

Creates a new Client instance.

Gets client’s payer.

Gets the internal Anchor client to call Anchor client’s methods directly.

Creates Program instance to communicate with the selected program.

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

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.

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.

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.

Returns all information associated with the account of the provided Pubkey.

Errors

It fails when the Solana cluster is not running.

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?)
}

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?
}

Airdrops lamports to the chosen account.

Get balance of an account

Get token balance of an token account

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 program
  • program_name - Name of the program to be deployed
Example:

Project structure

project/
- programs/
  - awesome_contract/
    - ...
    - Cargo.toml
  - turnstile/
    - ...
    - Cargo.toml
- ...
- Cargo.toml

Code

client.deploy_program(program_keypair(0), "awesome_contract");
client.deploy_program(program_keypair(1), "turnstile");

Creates accounts.

Creates rent exempt account.

Executes a transaction constructing a token mint.

Executes a transaction that mints tokens from a mint to an account belonging to that mint.

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.

Executes a transaction constructing the associated token account of the specified mint belonging to the owner. This will fail if the account already exists.

Executes a transaction creating and filling the given account with the given data. The account is required to be empty and will be owned by bpf_loader afterwards.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

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

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more