Skip to main content

Crate solana_client_wasip2

Crate solana_client_wasip2 

Source
Expand description

§solana-client-wasip2

A Solana JSON-RPC client for WebAssembly components (wasm32-wasip2). The official solana-client / solana-sdk stack does not build for that target — it pulls in reqwest/tokio and other host-only machinery. This crate provides the piece with no upstream equivalent there: a JSON-RPC client that speaks over the host’s wasi:http, returning Anza’s official RPC types.

It was written for ZeroClaw tool plugins, where TLS and the socket are provided by the host’s wasi:http and the guest only speaks HTTP.

§What it does

  • Query the chain — the full JSON-RPC method surface (rpc).
  • Submit & confirm — send_and_confirm_transaction and the confirmation pollers, with automatic retry/backoff on transient failures, a configurable transport timeout, and a client-level default commitment.

Building and signing transactions is out of scope — see below. This crate never signs.

§How the RPC client fits together

caller ── RpcClient::get_balance(..)            (rpc::methods)
           │  builds params, picks a method name
           ▼
         RpcClient dispatch + retry              (rpc::client)  ← the engine
           │  frames the JSON-RPC request, sequences ids,
           │  extracts `result` / surfaces `error`, deserializes
           ▼
         RpcTransport::post(url, body)         (transport)    ← the seam
           ├─ WakiTransport   → wasi:http      (only on wasm targets)
           └─ MockTransport   → canned reply   (host tests)

§Building a transaction

This crate is an RPC client; it does not build or sign transactions. The upstream SDK crates do that, and they compile for wasm32-wasip2, so add the ones you need directly (they are ordinary dependencies you own and version):

solana-system-interface = { version = "3", features = ["bincode"] } # transfer, etc.
solana-keypair = "3"                                                  # signing keys
solana-signer = "3"
spl-token-interface = "3"                                             # SPL builders

Compile a v0 message, sign into a VersionedTransaction, and hand it to RpcClient::send_transaction — which takes the typed transaction and serializes it internally, so the caller needs no bincode. Building an unsigned transaction (to propose for external signing) needs no key: construct a VersionedTransaction with default signature placeholders. The message and transaction types the RPC methods speak are re-exported here (see below) so they match versions with no effort.

§Module map

The RPC client (this crate’s own code):

The upstream types that appear in method signatures, re-exported under their conventional names so callers can name them without version-matching: pubkey, hash, signature, message, transaction, commitment_config.

A separate tests/rpc_coverage.rs diffs our method list against Anza’s canonical RpcRequest enum, so a newly-added upstream method fails the build until it is implemented or explicitly skipped.

Re-exports§

pub use error::*;
pub use rpc::*;
pub use transport::*;

Modules§

commitment_config
solana-commitment-config — commitment levels.
error
The single error type returned throughout the crate.
hash
solana-hash — 32-byte hashes / blockhashes.
message
solana-message — legacy and v0 messages (the input to get_fee_for_message).
pubkey
solana-pubkey — addresses and PDA derivation.
rpc
The RPC layer, split into four parts:
signature
solana-signature — transaction signatures.
transaction
solana-transaction — legacy and versioned transactions (the input to send_transaction / simulate_transaction).
transport
The HTTP seam between the JSON-RPC engine and the outside world.

Structs§

CommitmentConfig

Enums§

CommitmentLevel
An attribute of a slot. It describes how finalized a block is at some point in time. For example, a slot is said to be at the max level immediately after the cluster recognizes the block at that slot as finalized. When querying the ledger state, use lower levels of commitment to report progress and higher levels to ensure state changes will not be rolled back.