Install
The pubsub feature is off by default — opt in only if you need WebSocket subscriptions. HTTP-only consumers ship a smaller wasm bundle.
HTTP usage
use WasmClient;
let client = new;
let slot = client.get_slot.await?;
let version = client.get_version.await?;
let latest = client.get_latest_blockhash.await?;
Address-taking methods (e.g. get_balance, get_account_info) take &Address:
use address;
let owner = address!;
let balance = client.get_balance.await?.value;
See src/methods.rs for the full list of RPC methods.
Response size limit
HTTP responses are capped at 10 MiB by default so a misconfigured or
malicious RPC can't OOM the wasm runtime with a multi-gigabyte body. Tune the
limit with .with_max_response_size(bytes):
// 50 MiB for `getProgramAccounts` on a busy program:
let client = new
.with_max_response_size;
Oversized responses are rejected with RpcError::RpcRequestError("response body too large …") — pre-flight via Content-Length, or post-read for chunked encoding.
WebSocket / PubSub usage
Requires the
pubsubfeature.
use ;
let client = connect?;
// Stream of typed notifications:
let mut sub = client.slot_subscribe.await?;
while let Some = sub.next.await
// Explicit unsubscribe awaits the server's ack; dropping the subscription
// fires a best-effort unsubscribe instead.
sub.unsubscribe.await?;
Supported subscriptions: account, block, logs, program, root, signature, slot, slotsUpdates, vote. See src/pubsub_methods.rs.
Example
examples/leptos-slot-monitor is a small Leptos CSR app that streams the live devnet slot via WebSocket and fetches the node version via HTTP:
Development
The test recipe expects surfpool, wasm-bindgen-cli@0.2.121, just, and Node 22+ in PATH. The repo's rust-toolchain.toml auto-installs the stable toolchain with the wasm32-unknown-unknown target.
CI runs fmt, clippy (on both --all-features and --no-default-features), and the wasm test suite on every push; see .github/workflows/ci.yml.