Rust Wallet Adapter for Solana Dapps.
The wallet-adapter library is a Rust crate that performs actions between a Rust WebAssembly frontend and browser wallet extensions that implement the wallet-standard.
Links
Features
It implements the following from wallet-standard:
-
standard:connect- Performs a connection operation to a browser wallet -
standard:disconnect- Performs a connection operation to a browser wallet -
standard:events- Listens for connected and disconnected events emitted from a wallet. -
solana:signIn- Performs a Sign In With Solana (SIWS) operations for wallet authentication/authorization. -
solana:signMessage- An operation that signs a message -
solana:signTransaction- An operation that signs a transaction -
solana:signAndSendTransaction- an operation that signs a transaction and sends it to a Solana RPC.
Any wallet that implements the wallet-standard will be detected by this crate.
Events
Wallets register themselves by listening for one or both of these browser custom events as defined by the wallet-standard.
-
wallet-standard:register-wallet- listens for wallets that emit browser window event as a way to register themselves. -
wallet-standard:app-ready- the library dispatches this event in order to inform browser extension wallets that the frontend application is ready to receive registration events.
Building the library without a template
The wallet-adapter crate uses the browser's cryptographically secure random number generator to generate random values using the getrandom,rand-core and rand-chacha crates.
The getrandom crate needs to understand the backend to use as described in their docs which require the use of rustc flag RUSTFLAGS='--cfg getrandom_backend="wasm_js"' to be specified when running cargo build --target wasm32-unknown-unknown.
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' cargo build --target wasm32-unknown-unknown
Therefore, if you are not using the template which automatically generates the config file for you, you need to add a .cargo/config.toml file in your root directory (the config file needs to be in the workspace root if you are using a cargo workspace).
See the structure of the .cargo Rust config dir.
The .cargo/config.toml file should contain this.
[target.wasm32-unknown-unknown]
rustflags = ["--cfg", "getrandom_backend=\"wasm_js\""]