8 stable releases

1.18.0 Mar 10, 2024
1.17.4 Nov 4, 2023
1.17.2 Oct 17, 2023
1.16.5 Jul 25, 2023
1.11.0-beta Jul 19, 2022

#17 in #wasm-client

Download history 25/week @ 2024-06-10 57/week @ 2024-06-17 20/week @ 2024-06-24 9/week @ 2024-07-01 29/week @ 2024-07-08 80/week @ 2024-07-15 131/week @ 2024-07-22 15/week @ 2024-07-29 78/week @ 2024-09-23

78 downloads per month
Used in wasi-sol

Apache-2.0

750KB
16K SLoC

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;

Dependencies

~24–39MB
~666K SLoC