Expand description
A Solana Wallet adapter for WASM frameworks.
§🔒 Wallets Support
| Wallet | Supported | Features |
|---|---|---|
| Phantom | ✅ | All |
| Solflare | ✅ | All |
| Backpack | ✅ | All |
§🌐 Wasm Frameworks Support
| Framework | Supported |
|---|---|
| Yew | ✅ |
| Dioxus | ✅ |
| Leptos | ✅ |
§⚙️ Features
| Method | Supported | Tested |
|---|---|---|
connect | ✅ | ✅ |
disconnect | ✅ | ✅ |
sign_in | ✅ | ✅ |
sign_message | ✅ | ✅ |
sign_transaction | ✅ | ✅ |
send_transaction | ✅ | ✅ |
§🔥 Getting Started
Wasi Sol provides providers and hooks that you can use to bring all wallet adapter functionalities to your app. To begin, wrap your main App component with the corresponding providers:
// Yew Component
#[function_component]
pub fn App() -> Html {
let endpoint = "https://api.mainnet-beta.solana.com";
let wallets = vec![
Wallet::Phantom.into(),
Wallet::Solflare.into(),
Wallet::Backpack.into(),
];
html! {
<ConnectionProvider {endpoint}>
<WalletProvider {wallets}>
<LoginPage />
</WalletProvider>
</ConnectionProvider>
}
}This will allow you to use the hooks to create the wallet adapter that exists in the wallets vector:
// Yew Component
#[function_component]
pub fn LoginPage() -> Html {
let phantom_context = use_wallet::<Wallet>(Wallet::Phantom);
let solflare_context = use_wallet::<Wallet>(Wallet::Solflare);
let backpack_context = use_wallet::<Wallet>(Wallet::Backpack);
// ...snip...
html! {
<>
</>
}
}Now you can choose the wallets you want to add to allow users to connect to. Wasi Sol comes with built-in reusable components that encapsulate all connect and disconnect logic so that you can develop web apps quickly:
// Yew Component
#[function_component]
pub fn LoginPage() -> Html {
// ...snip...
html! {
<LoginForm
phantom={Some(phantom_wallet_adapter)}
solflare={Some(solflare_wallet_adapter)}
backpack={None}
{connected}
/>
}
}This will select the Phantom and Solflare wallets and allow users to connect them to the app. The Backpack wallet is disabled in this case.
More detailed implementations can be found in the examples below.
§🚀 Examples
§🎧 Event Listener
This crate implements a handy event listener pattern with a built-in emitter object that you can use to subscribe to particular events. This functionality allows you to set state in the UI, perform actions on wallet connect, and more.
// Yew Component
// ...snip...
#[function_component]
pub fn LoginPage() -> Html {
let wallet_context = use_wallet();
let connected = use_state(|| false);
let wallet_adapter = use_state(|| wallet_context);
let connect_wallet = {
// ...snip...
Callback::from(move |_| {
// ...snip...
spawn_local(async move {
let mut wallet_info = (*wallet_adapter).clone();
wallet_info.emitter.on("connect", move |public_key: Pubkey| {
log::info!("Event Listener: Got pubkey {}", public_key);
wallet_adapter.set(wallet_info);
connected.set(true);
});
match wallet_info.connect().await {
Ok(_) => {
}
Err(err) => {
log::error!("Failed to connect wallet: {}", err);
}
}
});
})
};
// ...snip...
html! {
<>
</>
}
}§👥 Contributing
Contributions and feedback are welcome! If you’d like to contribute, report an issue, or suggest an enhancement, please engage with the project on GitHub. Your contributions help improve this library for the community.
§📝 License
This project is licensed under the MIT License.
Modules§
- The Solana
Accounttype. - Account information.
- Useful extras for
Accountstate. - address_lookup_table_accountDeprecated
- Hashing with the blake3 hash function.
- Utilities for the borsh serialization format.
- Utilities for the borsh serialization format, version 0.9.
- Utilities for the borsh serialization format, version 0.10.
- Utilities for the borsh serialization format, version 1.
- The latest BPF loader native program.
- The original and now deprecated Solana BPF loader.
- An upgradeable BPF loader native program.
- Another Base58 codec implementation.
- client
fullDefines traits for blocking (synchronous) and non-blocking (asynchronous) communication with a Solana server as well a a trait that encompasses both. - Information about the network’s clock, ticks, slots, etc.
- Definitions of commitment levels.
- compute_budget
fullThe compute budget native program. - Debug-formatting of account data.
- Converting custom error codes to enums.
- BIP-44 derivation paths.
- Serde helpers.
- Instructions for the ed25519 native program.
- The Rust-based BPF program entrypoint supported by the latest BPF loader.
- The Rust-based BPF program entrypoint supported by the original BPF loader.
- Information about the current epoch.
- A type to hold data for the
EpochRewardssysvar. - Configuration for epochs and slots.
- Used by validators to run events on exit.
- Methods for working with
Featureaccounts. - Collection of all runtime features.
- Fee structures.
- Calculation of transaction fees.
- genesis_config
fullThe chain’s genesis config. - hard_forks
fullThe list of slot boundaries at which a hard fork should occur. - A designated address for burning lamports.
- configuration for network inflation
- Types for directing the execution of Solana programs.
- Hashing with the keccak (SHA-3) hash function.
- Defines the
LamportsErrortype. - Instructions for the non-upgradable BPF loader.
- Instructions for the upgradable BPF loader.
- The v4 built-in loader program.
- Instructions for the v4 built-in loader program.
- Sequences of
Instructions executed within a single transaction. - The native loader native program.
- Definitions for the native SOL token and its fractional lamports.
- Durable transaction nonces.
- Functions related to nonce accounts.
- offchain_message
fullOff-chain message container for storing non-transaction messages. - The definition of a Solana network packet.
- Definitions of Solana’s proof of history.
- Hashing with the Poseidon hash function.
- precompiles
fullSolana precompiled programs. - Cross-program invocation.
- The
ProgramErrortype and related definitions. - Basic low-level memory operations.
- A C representation of Rust’s
Option, used across the FFI boundary for Solana program interfaces. - The
Packserialization trait. - program_stubsNon-
target_os="solana"Implementations of syscalls used whensolana-programis built for non-SBF targets. - Contains a single utility function for deserializing from bincode.
- Solana account addresses.
- quic
fullDefinitions related to Solana over QUIC. - Helpers for the recent blockhashes sysvar.
- Configuration for network rent.
- Enumeration of reward types.
- RPC default port numbers.
- A trait for sanitizing values and members of over the wire messages.
- A vector of Solana SDK IDs.
- Instructions for the secp256k1 native program.
- Public key recovery from secp256k1 ECDSA signatures.
- Integers that serialize to variable size.
- Helpers for reading and writing bytes.
- Compact serde-encoding of vectors with small length.
- shred_version
fullCalculation of shred versions. - signature
fullFunctionality for public and private keys. - signer
fullAbstractions and implementations for transaction signers. - A type to hold data for the
SlotHashessysvar. - A type to hold data for the
SlotHistorysysvar. - The stake native program.
- A type to hold data for the
StakeHistorysysvar. - Declarations of Solana program syscalls.
- Instructions and constructors for the system program.
- The
system_transactionmodule provides functionality for creating system transactions. - Access to special accounts with dynamically-updated data.
- The
timingmodule provides std::time utility functions. - transaction
fullAtomically-committed sequences of instructions. - Data shared between program runtime and built-in programs as well as SBF programs.
- transport
fullDefines theTransportErrortype. - The vote native program.
Macros§
- Define the default global allocator.
- Define the default global panic handler.
- Same as
declare_sysvar_idexcept that it reports that this ID has been deprecated. - Declares an ID that implements
SysvarId. - entrypointDeprecated
- entrypoint_deprecatedDeprecated
- Implements the
Sysvar::getmethod for both SBF and host targets. - Print a message to the log.
- program_stubsDeprecated
- A proc-macro which respans the tokens in its first argument (a
Path) to be resolved at the tokens of its second argument. For internal use only. - Convenience macro for
AddAssignwith saturating arithmetic. Replace bystd::num::Saturatingonce stable - Convenience macro for doing integer division where the operation’s safety can be checked at compile-time.
Functions§
- Runs a Rust
Futureon the current thread.