A lightweight, type-safe Solana wallet adapter for Rust-based frontends and WebAssembly applications
Documentation β’ Features β’ Quick Start β’ Examples β’ Contributing
wallet-adapter is a pure Rust implementation of the Solana Wallet Standard, designed for building WebAssembly-based dApps with frameworks like Dioxus, Yew, and Sycamore. It provides a type-safe, async-first API for connecting to browser wallet extensions and interacting with the Solana blockchain.
- β Full Wallet Standard Compliance - Implements all standard wallet features
- β Type-Safe API - Leverages Rust's type system for compile-time safety
- β Async/Await Support - Built on async primitives for modern Rust applications
- β
Zero Unsafe Code -
#![forbid(unsafe_code)]enforced throughout - β Framework Templates - Ready-to-use templates for Dioxus, Yew, and Sycamore
- β Comprehensive Error Handling - Detailed error types for all failure modes
- β Event-Driven Architecture - Reactive wallet state management
Add wallet-adapter to your Cargo.toml:
[dependencies] wallet-adapter = "1.1.2" web-sys = { version = "0.3", features = [ "Window", "Document", "Event", "EventTarget", "CustomEvent", ] } wasm-bindgen-futures = "0.4"use wallet_adapter::{WalletAdapter, WalletResult}; async fn connect_wallet() -> WalletResult<()> { // Initialize the wallet adapter let mut adapter = WalletAdapter::init()?; // Connect to a wallet by name adapter.connect_by_name("Phantom").await?; // Get connection info let connection = adapter.connection_info().await; let account = connection.connected_account()?; println!("Connected to: {}", account.address()); Ok(()) }- Full Documentation Book - Complete guide with examples
- API Documentation - Auto-generated API docs
- Templates Guide - Framework-specific templates
The adapter can be initialized in several ways:
// Default initialization (channel capacity: 5) let adapter = WalletAdapter::init()?; // Custom channel capacity let adapter = WalletAdapter::init_with_channel_capacity(10)?; // With custom Window and Document let window = web_sys::window().unwrap(); let document = window.document().unwrap(); let adapter = WalletAdapter::init_custom(window, document)?;Listen for wallet events asynchronously:
let adapter = WalletAdapter::init()?; let event_receiver = adapter.events(); while let Ok(event) = event_receiver.recv().await { match event { WalletEvent::Registered(wallet) => { println!("Wallet registered: {}", wallet.name()); } WalletEvent::Connected(account) => { println!("Connected: {}", account.address()); } WalletEvent::Disconnected => { println!("Wallet disconnected"); } _ => {} } }// Connect by wallet name adapter.connect_by_name("Phantom").await?; // Or iterate through available wallets for wallet in adapter.wallets() { if wallet.name() == "Phantom" { adapter.connect(wallet).await?; break; } }// Check cluster support let supports_mainnet = adapter.mainnet().await?; let supports_devnet = adapter.devnet().await?; // Check feature support let supports_sign_message = adapter.solana_sign_message().await?; let supports_sign_transaction = adapter.solana_sign_transaction().await?; let supports_sign_and_send = adapter.solana_sign_and_send_transaction().await?;use wallet_adapter::{WalletAdapter, SigninInput, Cluster}; async fn sign_in() -> WalletResult<()> { let mut adapter = WalletAdapter::init()?; adapter.connect_by_name("Phantom").await?; let public_key = adapter.connection_info().await .connected_account()?.public_key(); let address = adapter.connection_info().await .connected_account()?.address().to_string(); let mut signin_input = SigninInput::new(); signin_input .set_domain(&adapter.window())? .set_statement("Login to My DApp") .set_chain_id(Cluster::DevNet) .set_address(&address)?; let signin_output = adapter.sign_in(&signin_input, public_key).await?; Ok(()) }async fn sign_message() -> WalletResult<()> { let mut adapter = WalletAdapter::init()?; adapter.connect_by_name("Phantom").await?; if adapter.solana_sign_message().await? { let output = adapter.sign_message(b"Hello, Solana!").await?; println!("Signature: {}", output.signature); } Ok(()) }use solana_sdk::{ native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, system_instruction, transaction::Transaction, }; use wallet_adapter::{WalletAdapter, Cluster}; async fn sign_transaction() -> WalletResult<()> { let mut adapter = WalletAdapter::init()?; adapter.connect_by_name("Phantom").await?; let public_key = adapter.connection_info().await .connected_account()?.public_key(); let pubkey = Pubkey::new_from_array(public_key); let recipient = Pubkey::new_unique(); let instruction = system_instruction::transfer(&pubkey, &recipient, LAMPORTS_PER_SOL); let tx = Transaction::new_with_payer(&[instruction], Some(&pubkey)); let tx_bytes = bincode::serialize(&tx)?; let signed_tx = adapter.sign_transaction(&tx_bytes, Some(Cluster::DevNet)).await?; Ok(()) }use wallet_adapter::{WalletAdapter, Cluster, SendOptions}; async fn sign_and_send() -> WalletResult<()> { let mut adapter = WalletAdapter::init()?; adapter.connect_by_name("Phantom").await?; // ... build transaction ... let send_options = SendOptions::default(); let signature = adapter.sign_and_send_transaction( &tx_bytes, Cluster::DevNet, send_options ).await?; println!("Transaction signature: {}", signature); Ok(()) }Ready-to-use templates for popular Rust frontend frameworks:
- Dioxus Template - Full-featured Dioxus integration
- Yew Template - Yew component library
- Sycamore Template - Sycamore reactive components
- Anchor Integration Templates - Templates with Anchor program integration
Each template includes:
- Complete wallet connection UI
- Transaction signing flows
- Account management
- Network switching
- Error handling
- Modern, responsive design
- β
wallet-standard:register-wallet- Wallet registration - β
wallet-standard:app-ready- App readiness notification - β
standard:connect- Connect to wallet - β
standard:disconnect- Disconnect from wallet - β
standard:events- Wallet event subscription
- β
solana:signIn- Sign In With Solana (SIWS) - β
solana:signMessage- Message signing - β
solana:signTransaction- Transaction signing - β
solana:signAndSendTransaction- Sign and send transactions
- β Multi-cluster support (Mainnet, Devnet, Testnet, Localnet)
- β Commitment level configuration
- β Wallet account parsing and validation
- β Ed25519 signature verification
- β In-memory wallet storage
- β Comprehensive error types
Wallets are stored in-memory using a HashMap keyed by wallet name hash:
use wallet_adapter::WalletStorage; let storage = WalletStorage::default(); let wallets = storage.get_wallets(); let phantom = storage.get_wallet("Phantom");Connection state is managed through ConnectionInfo:
let connection = adapter.connection_info().await; let wallet = connection.connected_wallet()?; let account = connection.connected_account()?;All operations return WalletResult<T>, which is Result<T, WalletError>. The error type provides detailed information about failures:
match adapter.connect_by_name("Phantom").await { Ok(_) => println!("Connected!"), Err(WalletError::WalletNotFound) => println!("Wallet not installed"), Err(WalletError::WalletConnectError(msg)) => println!("Connection failed: {}", msg), Err(e) => println!("Error: {}", e), }. βββ crate/ # Main library crate β βββ src/ β βββ adapter.rs # WalletAdapter implementation β βββ errors.rs # Error types β βββ events.rs # Event handling β βββ storage.rs # Wallet storage β βββ utils.rs # Utility functions β βββ wallet_ser_der/ # Wallet serialization/deserialization βββ templates/ # Framework templates β βββ dioxus-adapter/ β βββ yew-adapter/ β βββ sycamore-adapter/ βββ wallet-adapter-book/ # Documentation book βββ partial-idl-parser/ # IDL parser utility Contributions are welcome! Please read our contributing guidelines and code of conduct.
# Clone the repository git clone https://github.com/yourusername/solana-wallet-adapter-rust.git cd solana-wallet-adapter-rust # Build the project cargo build # Run tests cargo test # Check code quality cargo clippy cargo fmtAll contributors must agree to the Rust Code of Conduct.
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
- Built for the Solana ecosystem
- Implements the Wallet Standard
- Inspired by the JavaScript wallet adapter ecosystem
- Telegram: @moooncity
- Issues: GitHub Issues
- Documentation: Full Book
Built with β€οΈ for the Rust and Solana communities
β Star us on GitHub β’ π Read the Docs β’ π¬ Get Support