Crates.io | solana-client-wasm |
lib.rs | solana-client-wasm |
version | 1.18.0 |
source | src |
created_at | 2022-07-07 17:27:48.030947 |
updated_at | 2024-03-10 21:34:21.600586 |
description | Solana non-blocking WASM RPC client. |
homepage | https://beta.solpg.io |
repository | https://github.com/solana-playground/solana-playground |
max_upload_size | |
id | 621300 |
size | 192,382 |
Non-blocking implementation of WASM compatible Solana Client.
Most methods are identical to solana-client non-blocking API.
solana-sdk is exported which means you don't need to add it to your dependencies.
use solana_client_wasm::{
solana_sdk::signature::{Keypair, Signer},
WasmClient,
};
// Create client
let client = WasmClient::new("https://api.devnet.solana.com");
// Get a random pubkey
let pubkey = Keypair::new().pubkey();
// Get balance
let balance = client.get_balance(&pubkey).await?; // in lamports
log::info!("Balance is {balance}"); // 0
Requires pubsub
crate feature to be activated.
Current implementation depends on web-sys and js-sys crates and is intended to work only in browsers.
// Create a client
let client = WasmClient::new("https://api.devnet.solana.com");
// Subscribe to changes
let id = client
.account_subscribe(pubkey, |data| {
// Handle change...
})
.await;
// Unsubscribe when its no longer being used to prevent memory leak
client.account_unsubscribe(id).await;