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Β§
- account
- The Solana
Accounttype. - account_
info - Account information.
- account_
utils - Useful extras for
Accountstate. - address_
lookup_ table - The address lookup table program.
- address_
lookup_ table_ account Deprecated - alt_
bn128 - big_
mod_ exp - blake3
- Hashing with the blake3 hash function.
- borsh
- Utilities for the borsh serialization format.
- borsh0_
9 - Utilities for the borsh serialization format, version 0.9.
- borsh0_
10 - Utilities for the borsh serialization format, version 0.10.
- borsh1
- Utilities for the borsh serialization format, version 1.
- bpf_
loader - The latest BPF loader native program.
- bpf_
loader_ deprecated - The original and now deprecated Solana BPF loader.
- bpf_
loader_ upgradeable - An upgradeable BPF loader native program.
- bs58
- Another Base58 codec implementation.
- client
- Defines traits for blocking (synchronous) and non-blocking (asynchronous) communication with a Solana server as well a a trait that encompasses both.
- clock
- Information about the networkβs clock, ticks, slots, etc.
- commitment_
config - Definitions of commitment levels.
- compute_
budget - The compute budget native program.
- config
- The config native program.
- core
- debug_
account_ data - Debug-formatting of account data.
- decode_
error - Converting custom error codes to enums.
- derivation_
path - BIP-44 derivation paths.
- deserialize_
utils - Serde helpers.
- ed25519_
instruction - Instructions for the ed25519 native program.
- ed25519_
program - The ed25519 native program.
- entrypoint
- The Rust-based BPF program entrypoint supported by the latest BPF loader.
- entrypoint_
deprecated - The Rust-based BPF program entrypoint supported by the original BPF loader.
- epoch_
info - Information about the current epoch.
- epoch_
rewards - A type to hold data for the
EpochRewardssysvar. - epoch_
rewards_ hasher - epoch_
rewards_ partition_ data - epoch_
schedule - Configuration for epochs and slots.
- exit
- Used by validators to run events on exit.
- feature
- Methods for working with
Featureaccounts. - feature_
set - Collection of all runtime features.
- fee
- Fee structures.
- fee_
calculator - Calculation of transaction fees.
- forms
- genesis_
config - The chainβs genesis config.
- hard_
forks - The list of slot boundaries at which a hard fork should occur.
- hash
- Hashing with the SHA-256 hash function, and a general
Hashtype. - incinerator
- A designated address for burning lamports.
- inflation
- configuration for network inflation
- inner_
instruction - instruction
- Types for directing the execution of Solana programs.
- keccak
- Hashing with the keccak (SHA-3) hash function.
- lamports
- Defines the
LamportsErrortype. - loader_
instruction - Instructions for the non-upgradable BPF loader.
- loader_
upgradeable_ instruction - Instructions for the upgradable BPF loader.
- loader_
v4 - The v4 built-in loader program.
- loader_
v4_ instruction - Instructions for the v4 built-in loader program.
- message
- Sequences of
Instructions executed within a single transaction. - native_
loader - The native loader native program.
- native_
token - Definitions for the native SOL token and its fractional lamports.
- net
- nonce
- Durable transaction nonces.
- nonce_
account - Functions related to nonce accounts.
- offchain_
message - Off-chain message container for storing non-transaction messages.
- packet
- The definition of a Solana network packet.
- poh_
config - Definitions of Solanaβs proof of history.
- poseidon
- Hashing with the Poseidon hash function.
- precompiles
- Solana precompiled programs.
- program
- Cross-program invocation.
- program_
error - The
ProgramErrortype and related definitions. - program_
memory - Basic low-level memory operations.
- program_
option - A C representation of Rustβs
Option, used across the FFI boundary for Solana program interfaces. - program_
pack - The
Packserialization trait. - program_
stubs - Implementations of syscalls used when
solana-programis built for non-SBF targets. - program_
utils - Contains a single utility function for deserializing from bincode.
- provider
- pubkey
- Solana account addresses.
- quic
- Definitions related to Solana over QUIC.
- recent_
blockhashes_ account - Helpers for the recent blockhashes sysvar.
- rent
- Configuration for network rent.
- reward_
type - Enumeration of reward types.
- rpc_
port - RPC default port numbers.
- sanitize
- A trait for sanitizing values and members of over the wire messages.
- sdk_ids
- A vector of Solana SDK IDs.
- secp256k1_
instruction - Instructions for the secp256k1 native program.
- secp256k1_
program - The secp256k1 native program.
- secp256k1_
recover - Public key recovery from secp256k1 ECDSA signatures.
- serde_
varint - Integers that serialize to variable size.
- serialize_
utils - Helpers for reading and writing bytes.
- short_
vec - Compact serde-encoding of vectors with small length.
- shred_
version - Calculation of shred versions.
- signature
- Functionality for public and private keys.
- signer
- Abstractions and implementations for transaction signers.
- simple_
vote_ transaction_ checker - slot_
hashes - A type to hold data for the
SlotHashessysvar. - slot_
history - A type to hold data for the
SlotHistorysysvar. - stake
- The stake native program.
- stake_
history - A type to hold data for the
StakeHistorysysvar. - syscalls
- Declarations of Solana program syscalls.
- system_
instruction - Instructions and constructors for the system program.
- system_
program - The system native program.
- system_
transaction - The
system_transactionmodule provides functionality for creating system transactions. - sysvar
- Access to special accounts with dynamically-updated data.
- timing
- The
timingmodule provides std::time utility functions. - transaction
- Atomically-committed sequences of instructions.
- transaction_
context - Data shared between program runtime and built-in programs as well as SBF programs.
- transport
- Defines the
TransportErrortype. - vote
- The vote native program.
MacrosΒ§
- custom_
heap_ default - Define the default global allocator.
- custom_
panic_ default - Define the default global panic handler.
- declare_
deprecated_ id - declare_
deprecated_ sysvar_ id - Same as
declare_sysvar_idexcept that it reports that this ID has been deprecated. - declare_
id - declare_
sysvar_ id - Declares an ID that implements
SysvarId. - entrypoint
Deprecated - entrypoint_
deprecated Deprecated - impl_
sysvar_ get - Implements the
Sysvar::getmethod for both SBF and host targets. - msg
- Print a message to the log.
- program_
stubs Deprecated - pubkey
- pubkeys
- respan
- 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. - saturating_
add_ assign - Convenience macro for
AddAssignwith saturating arithmetic. Replace bystd::num::Saturatingonce stable - unchecked_
div_ by_ const - Convenience macro for doing integer division where the operationβs safety can be checked at compile-time.
FunctionsΒ§
- spawn_
local - Runs a Rust
Futureon the current thread.
Attribute MacrosΒ§
- wasm_
bindgen - A list of all the attributes can be found here: https://rustwasm.github.io/docs/wasm-bindgen/reference/attributes/index.html