18 releases (6 breaking)

0.7.0 Nov 4, 2024
0.6.1 Oct 20, 2024
0.5.1 Oct 13, 2024
0.4.0 Oct 11, 2024
0.1.3 Sep 18, 2024

#1054 in Web programming

Download history 205/week @ 2024-09-07 294/week @ 2024-09-14 173/week @ 2024-09-21 443/week @ 2024-09-28 889/week @ 2024-10-05 468/week @ 2024-10-12 321/week @ 2024-10-19 15/week @ 2024-10-26 135/week @ 2024-11-02 15/week @ 2024-11-09

499 downloads per month
Used in test_utils_solana

Unlicense

1MB
25K SLoC

wasm_client_anchor


A wasm compatible anchor client.


Crate Docs Status Unlicense codecov

Installation

To install you can used the following command:

cargo add wasm_client_anchor

Or directly add the following to your Cargo.toml:

[dependencies]
wasm_client_anchor = "0.1" # replace with the latest version

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 using in a server or non-browser environment.

Usage

Use AnchorProgram to interact directly with anchor programs.

use solana_sdk::instruction::AccountMeta;
use solana_sdk::instruction::Instruction;
use solana_sdk::pubkey;
use solana_sdk::signature::Signature;
use solana_sdk::transaction::VersionedTransaction;
use wallet_standard_wallets::AnchorProgram;
use wallet_standard_wallets::AnchorRequestMethods;
use wallet_standard_wallets::WalletAnchor;
use wasm_client_anchor::AnchorClientResult;

async fn run() -> AnchorClientResult<()> {
	let program_id = pubkey!("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin");
	let anchor_program = AnchorProgram::builder()
		.rpc(rpc)
		.wallet(wallet)
		.program_id(program_id)
		.build();

	// sample instruction data
	let data = vec![0u8; 10];
	// sample accounts needed for the anchor program instruction
	let accounts = vec![AccountMeta::new(
		pubkey!("SysvarC1ock11111111111111111111111111111111"),
		false,
		true,
	)];

	// create an anchor request using the builder pattern
	let anchor_request = client.request().data(data).accounts(accounts).build();

	// get the instructions to be sent
	let instructions: Vec<Instruction> = anchor_request.instructions();

	// sign the transaction with the wallet as payer
	let versioned_transaction: VersionedTransaction =
		anchor_program.sign_transaction(anchor_request).await?;

	// send and send the transaction at the same time
	let signature: Signature = anchor_program
		.sign_and_send_transaction(anchor_request)
		.await?;

	Ok(())
}

Dependencies

~34–48MB
~816K SLoC