Wallet-Adapter
A lightweight Rust Solana Wallet that can be used in Rust based frontends and WebAssembly.
Maintenance
This crate is feature complete, implementing all standardized requirements of the wallet-adapter standard. Therefore, the crate is passively maintained. New features will be added if the wallet-adapter standard adds new features. Minor releases are expected for bug fixes.
Documentation Links
- Usage - How to add this library and required features for
web-syscrate - Initializing - How
AppReadyandRegisterwallet events are initialized - Wallet Storage - How the wallets registered are stored in memory within the dapp
- Connect and Check for Supported Features - How to connect to a browser wallet and check which features the connected wallet supports
- Disconnect - Disconnected an account from the connected wallet
- Sign In With Solana - Sign In With Solana (SIWS)
- Sign Message - Signing a message with a browser wallet
- Sign Transaction - Signing a transaction with a browser wallet
- Sign and Send Transaction - Sign and Send Transaction with a browser wallet
- Examples - Where to find examples
- License - Licensed under Apache-2.0 or MIT
- Features - What features of the wallet standard are supported by this library
- Templates - Which Rust frontend framework templates have been implemented
- Template Examples - Which Rust frontend framework templates examples have been implemented
- Build Requirement - What tools are required to build a working project
- Build and Run A Template - How to build a template or project to WebAssembly and run in the browser
Usage
Building the project requires a web-assembly environment.
See Template Usage for more details
Initializing Register and AppReady
This is done automatically when calling WalletAdapter::init(). The Register and AppReady events are registered to the browser window and document in the current page allowing browser extension wallet to register themselves as specified in the wallet standard.
use ;
async
In-memory storage for registered wallets.
wallet_adapter::WalletStorage handles storage of registered wallets. The in-memory storage is a HashMap<hash, Wallet>
where the hash is the hash of the wallet name.
use WalletStorage;
let storage = default;
// Get all registered wallets
storage.get_wallets;
// Get a wallet by its name
storage.get_wallet;
// Clone the storage inside a closure, method or function that moves variables out of their environment
// `WalletStorage` internally representation is `Rc<RefCell<HashMap<hash, Wallet>>>`
// this makes it cheap to clone `WalletStorage` where one needs to access `HashMap<hash, Wallet>`
storage.clone_inner;
Connecting to a browser extension wallet and checking for features
use ;
async
Disconnecting from the wallet
use ;
async
Sign In With Solana (SIWS)
use ;
async
Sign In With Solana (SIWS) supports more options for the Sign In With Solana Standard. Check the methods on the [SigninInput] struct. NOTE that an error is thrown by the library in case the message signed, public key don't match or if the signature is not valid for the signing public key.
Sign Message
All messages must be UTF-8 encoded string of bytes
use ;
async
NOTE that an error is thrown by the library in case the message, public key don't match or if the signature is not valid for the signing public key.
Sign Transaction
Here, we simulate signing a SOL transfer instruction
use ;
use ;
async
Remember to add the necessary dependencies for this part in the Cargo.toml manifest.
[]
# Add latest versions of these crates
= "^2.1.2"
= "^1.3.3"
NOTE that if the signed transaction is verified by the library and an error is thrown in case of signature mismatch.
Sign And Send Transaction
Here, we simulate signing and sending a SOL transfer instruction
use FromStr;
use ;
use Deserialize;
use ;
use JsFuture;
use ;
async
Remember to add the necessary dependencies for this part in the Cargo.toml manifest.
[]
# Add latest versions of these crates
= "^2.1.2"
= "^1.3.3"
= "^0.12.5"
= "1.0.133"
= { = "^1.0.215", = ["derive"] }
NOTE that if the signed transaction is verified by the library and an error is thrown in case of signature mismatch.
LICENSE
Apache-2.0 OR MIT
Features
- Register
wallet-standard:register-walletcustom event - App Ready
wallet-standard:app-readycustom event - Wallet Info
- Wallet Account parsing
- Wallet Icon
- Chains
- Clusters
- Version (Semver Versionin)
- Features
- Connect Wallet
standard:connect - Disconnect Wallet
standard:disconnect - SignIn (Sign In With Solana SIWS)
- Sign Message
- Sign Transaction
- Sign and Send Transaction
- Standard Events like Connect, Disconnect and (Re-connect & Account Changed (for wallets that support this)
Goals
- Cover the entire wallet-adapter spec for all required implementations
- Stable library that does not change much ensuring apps that build with this don't break on new changes
- Great documentation covering the library and all it's internal modules, types and methods
Templates
- Sycamore
- Yew
- Dioxus
Template Examples
- Sycamore
- Yew
- Dioxus
All templates can be found at the templates directory.
Learn how the templates work from https://github.com/JamiiDao/SolanaWalletAdapter/blob/master/templates/README.md
Code of conduct for contributions
All conversations and contributors must agree to Rust Code of Conduct