solana-client-wasm

Crates.iosolana-client-wasm
lib.rssolana-client-wasm
version1.18.0
sourcesrc
created_at2022-07-07 17:27:48.030947
updated_at2024-03-10 21:34:21.600586
descriptionSolana non-blocking WASM RPC client.
homepagehttps://beta.solpg.io
repositoryhttps://github.com/solana-playground/solana-playground
max_upload_size
id621300
size192,382
acheron (acheroncrypto)

documentation

README

Solana WASM Client

Crates.io License

Non-blocking implementation of WASM compatible Solana Client.

Usage

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.

Example

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

WebSocket

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;
Commit count: 1036

cargo fmt