| Crates.io | wasm_client_anchor |
| lib.rs | wasm_client_anchor |
| version | 0.8.1 |
| created_at | 2024-09-13 09:30:26.119152+00 |
| updated_at | 2025-03-14 17:46:56.322831+00 |
| description | A wasm compatible anchor client |
| homepage | https://github.com/ifiokjr/wasm_solana |
| repository | https://github.com/ifiokjr/wasm_solana |
| max_upload_size | |
| id | 1373521 |
| size | 186,484 |
wasm_client_anchorA wasm compatible anchor client.
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
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.Use AnchorProgram to interact directly with anchor programs.
use memory_wallet::AnchorProgram;
use memory_wallet::AnchorRequestMethods;
use memory_wallet::WalletAnchor;
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 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(())
}