Crate wasm_client_solana

Crate wasm_client_solana 

Source
Expand description

§wasm_client_solana


A WebAssembly (WASM) compatible client for interacting with the Solana RPC and PubSub APIs. It allows for sending transactions, fetching account data, subscribing to account changes, and more, from within a WASM compaitible environment like the web and serverless functions.


Crate Docs Status Unlicense codecov

§Installation

Add the following to your Cargo.toml:

[dependencies]
wasm_client_solana = "0.9"

Or use cargo add:

cargo add wasm_client_solana

§Building for WASM

When building your crate for the wasm32-unknown-unknown target, you need to set a specific RUSTFLAGS environment variable. This is required by the getrandom crate, a dependency used for generating random numbers, to correctly function in a WASM environment.

export RUSTFLAGS='--cfg getrandom_backend="wasm_js"'

Without this flag, you may encounter compilation errors related to getrandom.

§Features

This crate provides the following features:

  • js: Enables the use of the wasm-bindgen crate for the js target. This is useful for using the crate in a browser environment.
  • ssr: Enables the use of the reqwest and tokio crates for the ssr target. This is useful for using the crate in a server or non-browser environment.
  • zstd: Enables the use of the zstd as an encoding format and automatically activates the ssr target.

§Usage

The SolanaRpcClient provides a wasm compatible client for the solana rpc and pubsub methods.

use solana_sdk::native_token::sol_to_lamports;
use solana_sdk::pubkey;
use wasm_client_solana::ClientResult;
use wasm_client_solana::DEVNET;
use wasm_client_solana::SolanaRpcClient;

async fn run() -> ClientResult<()> {
	let client = SolanaRpcClient::new(DEVNET);
	let address = pubkey!("99P8ZgtJYe1buSK8JXkvpLh8xPsCFuLYhz9hQFNw93WJ");

	client
		.request_airdrop(&address, sol_to_lamports(1.0))
		.await?;
	let account = client.get_account(&address).await?;

	log::info!("account: {account:#?}");

	Ok(())
}

Re-exports§

pub use crate::utils::spawn_local;
pub use solana_account_decoder_client_types_wasm as solana_account_decoder_client_types;
pub use solana_account_decoder_wasm as solana_account_decoder;
pub use solana_transaction_status_client_types_wasm as solana_transaction_status_client_types;
pub use solana_transaction_status_wasm as solana_transaction_status;
pub use crate::rpc_config::*;

Modules§

nonce_utils
Durable transaction nonce helpers.
prelude
rpc_config
rpc_filter
rpc_response
runtime
utils

Structs§

BlockProductionRange
ClientRequest
ClientResponse
Context
ErrorValue
FeeForMessageValue
GetAccountInfoRequest
Use the builder pattern to create a request for account info.
GetAccountInfoResponse
GetBalanceRequest
GetBalanceResponse
GetBlockCommitmentRequest
GetBlockCommitmentResponse
GetBlockHeightRequest
GetBlockHeightResponse
GetBlockProductionRequest
GetBlockProductionResponse
GetBlockRequest
GetBlockResponse
GetBlockTimeRequest
GetBlockTimeResponse
GetBlocksRequest
GetBlocksResponse
GetBlocksWithLimitRequest
GetBlocksWithLimitResponse
GetClusterNodesRequest
GetClusterNodesResponse
GetEpochInfoRequest
GetEpochInfoResponse
GetEpochScheduleRequest
GetEpochScheduleResponse
GetFeeForMessageRequest
GetFeeForMessageResponse
GetFirstAvailableBlockRequest
GetFirstAvailableBlockResponse
GetGenesisHashRequest
GetGenesisHashResponse
GetHealthRequest
GetHealthResponse
GetHighestSnapshotSlotRequest
GetHighestSnapshotSlotResponse
GetIdentityRequest
GetIdentityResponse
GetInflationGovernorRequest
GetInflationGovernorResponse
GetInflationRateRequest
GetInflationRateResponse
GetInflationRewardRequest
GetInflationRewardResponse
GetLargestAccountsRequest
GetLargestAccountsResponse
GetLatestBlockhashRequest
GetLatestBlockhashResponse
GetLeaderScheduleRequest
GetLeaderScheduleResponse
GetMaxRetransmitSlotRequest
GetMaxRetransmitSlotResponse
GetMinimumBalanceForRentExemptionRequest
GetMinimumBalanceForRentExemptionResponse
GetMultipleAccountsRequest
GetMultipleAccountsResponse
GetProgramAccountsRequest
GetProgramAccountsResponse
GetRecentPerformanceSamplesRequest
GetRecentPerformanceSamplesResponse
GetRecentPrioritizationFeesRequest
GetRecentPrioritizationFeesResponse
GetSignatureStatusesRequest
GetSignatureStatusesResponse
GetSignaturesForAddressRequest
GetSignaturesForAddressResponse
GetSlotLeaderRequest
GetSlotLeaderResponse
GetSlotLeadersRequest
GetSlotLeadersResponse
GetSlotRequest
GetSlotResponse
GetStakeActivationRequest
GetStakeActivationResponse
GetStakeMinimumDelegationRequest
GetStakeMinimumDelegationResponse
GetSupplyRequest
GetSupplyResponse
GetTokenAccountBalanceRequest
GetTokenAccountBalanceResponse
GetTokenAccountsByDelegateRequest
GetTokenAccountsByDelegateResponse
GetTokenAccountsByOwnerRequest
GetTokenAccountsByOwnerResponse
GetTokenLargestAccountsRequest
GetTokenLargestAccountsResponse
GetTokenSupplyRequest
GetTokenSupplyResponse
GetTransactionCountRequest
GetTransactionCountResponse
GetTransactionRequest
GetTransactionResponse
GetVersionRequest
GetVersionResponse
GetVoteAccountsRequest
GetVoteAccountsResponse
HttpProvider
IsBlockhashValidRequest
IsBlockhashValidResponse
MinimumLedgerSlotRequest
MinimumLedgerSlotResponse
RequestAirdropRequest
RequestAirdropResponse
RpcContactInfoWasm
RpcError
SendTransactionRequest
SendTransactionResponse
SimulateTransactionRequest
SimulateTransactionResponse
SimulateTransactionResponseValue
SolanaRpcClient
A client of a remote Solana node.
Subscription
A Subscription is used to managed a solana websocket rpc method.
SubscriptionParams
SubscriptionResponse
TokenLargestAccountsValue
Unsubscription
Created from a Subscription to send a message to unsubscribe.
WebSocketProvider

Enums§

ClientError
ClientWebSocketError
Error returned by WebSocket

Constants§

COMPUTE_UNIT_DEFAULT_LIMIT
COMPUTE_UNIT_MAX_LIMIT
DEBUG
DEFAULT_ERROR_CODE
DEVNET
LOCALNET
MAINNET
MAX_LOOKUP_ADDRESSES_PER_TRANSACTION
MAX_RETRIES
SLEEP_MS
TESTNET

Traits§

HttpMethod
RpcProvider
ToWebSocketValue
VersionedMessageExtension
VersionedTransactionExtension
Add extensions which make it possible to partially sign a versioned transaction.
WebSocketMethod
WebSocketNotification

Functions§

initialize_address_lookup_table
Initialize a lookup table that can be used with versioned transactions.

Type Aliases§

ClientResult
SubscriptionId
SubscriptionResult
UnsubscriptionResult