#solana #rpc-client #interact #signer #cluster #mocking

anchor-client

An RPC client to interact with Anchor programs

51 releases (31 breaking)

0.32.1 Oct 10, 2025
0.31.1 Apr 20, 2025
0.31.0 Mar 9, 2025
0.30.1 Jun 20, 2024
0.3.0 Mar 12, 2021

#397 in Magic Beans

Download history 7227/week @ 2025-06-27 7134/week @ 2025-07-04 8593/week @ 2025-07-11 8899/week @ 2025-07-18 8241/week @ 2025-07-25 8015/week @ 2025-08-01 7674/week @ 2025-08-08 9169/week @ 2025-08-15 8899/week @ 2025-08-22 8532/week @ 2025-08-29 10728/week @ 2025-09-05 8927/week @ 2025-09-12 10507/week @ 2025-09-19 8809/week @ 2025-09-26 11761/week @ 2025-10-03 11932/week @ 2025-10-10

44,737 downloads per month
Used in 75 crates (66 directly)

Apache-2.0

51KB
1K SLoC

An RPC client to interact with Solana programs written in anchor_lang.

Examples

A simple example that creates a client, sends a transaction and fetches an account:

use std::rc::Rc;

use anchor_client::{
    solana_sdk::{
        signature::{read_keypair_file, Keypair},
        signer::Signer,
        system_program,
    },
    Client, Cluster,
};
use my_program::{accounts, instruction, MyAccount};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create client
    let payer = read_keypair_file("keypair.json")?;
    let client = Client::new(Cluster::Localnet, Rc::new(payer));

    // Create program
    let program = client.program(my_program::ID)?;

    // Send transaction
    let my_account_kp = Keypair::new();
    program
        .request()
        .accounts(accounts::Initialize {
            my_account: my_account_kp.pubkey(),
            payer: program.payer(),
            system_program: system_program::ID,
        })
        .args(instruction::Initialize { field: 42 })
        .signer(&my_account_kp)
        .send()?;

    // Fetch account
    let my_account: MyAccount = program.account(my_account_kp.pubkey())?;
    assert_eq!(my_account.field, 42);

    Ok(())
}

More examples can be found in here.

Features

async

The client is blocking by default. To enable asynchronous client, add async feature:

anchor-client = { version = "0.32.1 ", features = ["async"] }

mock

This feature allows passing in a custom RPC client when creating program instances, which is useful for mocking RPC responses, e.g. via RpcClient::new_mock.

Dependencies

~39–60MB
~1M SLoC