| Crates.io | wasm_client_solana |
| lib.rs | wasm_client_solana |
| version | 0.10.0 |
| created_at | 2024-09-13 09:29:14.86293+00 |
| updated_at | 2025-11-08 09:29:29.084403+00 |
| description | A wasm compatible solana rpc and pubsub client |
| homepage | https://github.com/ifiokjr/wasm_solana |
| repository | https://github.com/ifiokjr/wasm_solana |
| max_upload_size | |
| id | 1373520 |
| size | 442,359 |
wasm_client_solanaA WebAssembly (WASM) compatible client for interacting with the Solana RPC and PubSub APIs. It allows for sending transactions, fetching account data, subscribing to account changes, and more, from within a WASM compaitible environment like the web and serverless functions.
Add the following to your Cargo.toml:
[dependencies]
wasm_client_solana = "0.10.0"
Or use cargo add:
cargo add wasm_client_solana
When building your crate for the wasm32-unknown-unknown target, you need to set a specific RUSTFLAGS environment variable. This is required by the getrandom crate, a dependency used for generating random numbers, to correctly function in a WASM environment.
export RUSTFLAGS='--cfg getrandom_backend="wasm_js"'
Alternatively you can add this to your ./.cargo/config.toml file.
[target.wasm32-unknown-unknown]
rustflags = [
"--cfg",
"get_random_backend=\"wasm_js\"",
]
Without this flag, you may encounter compilation errors related to getrandom.
This crate provides the following features:
js: Enables the use of the wasm-bindgen crate for the js target. This is useful for using the crate in a browser environment.ssr: Enables the use of the reqwest and tokio crates for the ssr target. This is useful for using the crate in a server or non-browser environment.zstd: Enables the use of the zstd as an encoding format and automatically activates the ssr target.The SolanaRpcClient provides a wasm compatible client for the solana rpc and pubsub methods.
use solana_native_token::sol_str_to_lamports;
use solana_pubkey::pubkey;
use wasm_client_solana::ClientResult;
use wasm_client_solana::DEVNET;
use wasm_client_solana::SolanaRpcClient;
async fn run() -> ClientResult<()> {
let client = SolanaRpcClient::new(DEVNET);
let address = pubkey!("99P8ZgtJYe1buSK8JXkvpLh8xPsCFuLYhz9hQFNw93WJ");
client
.request_airdrop(&address, sol_str_to_lamports("1.0").unwrap())
.await?;
let account = client.get_account(&address).await?;
log::info!("account: {account:#?}");
Ok(())
}