Solana
Ready to call this in production?
Free tier covers personal projects. Pay-as-you-go scales without a card.
Solana
Free tier covers personal projects. Pay-as-you-go scales without a card.
For Solana in Rust, solana-client provides the RpcClient that speaks the JSON-RPC API, and solana-sdk provides the core types you build with — Pubkey, Keypair, Transaction, instructions, and CommitmentConfig. Add both crates to your Cargo.toml; these are the same libraries the validator and CLI are built on, so behavior matches the network exactly.
The crate ships two RpcClient variants. The blocking client lives in solana_client::rpc_client and is the simplest choice for scripts and tools. The async client lives in solana_client::nonblocking::rpc_client, exposes the same methods as async fns, and needs a Tokio runtime to run — add tokio with the full feature to your dependencies.
Build an RpcClient with new_with_commitment, passing the Solana endpoint https://solana.therpc.io/YOUR_API_KEY and a CommitmentConfig such as confirmed. get_balance returns the balance directly in lamports — divide by 1_000_000_000.0 for SOL — and get_account returns the full account, including the owner program that controls it.
To move SOL, create a System transfer instruction with system_instruction::transfer, fetch a fresh blockhash from get_latest_blockhash (Solana transactions expire quickly, so the blockhash must be recent), and assemble a signed Transaction with new_signed_with_payer. send_and_confirm_transaction broadcasts the transaction and blocks until the cluster confirms it, returning the signature.
RpcClient, the full solana-sdk type set, transaction signing, CommitmentConfig control, and program interaction.The nonblocking RpcClient from solana_client::nonblocking::rpc_client exposes the same API as the blocking one, but every method is an async fn you .await. Run it under a Tokio runtime — the #[tokio::main] attribute is the simplest way — so you can issue many Solana RPC calls concurrently without tying up OS threads.