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:
```ignore
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> {
// 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 a 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 an 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].
[here]: https://github.com/coral-xyz/anchor/tree/v0.30.1/client/example/src
# Features
The client is blocking by default. To enable asynchronous client, add `async` feature:
```toml
anchor-client = { version = "0.30.1 ", features = ["async"] }
````