Solana Wallet Adapter
Overview
The SWA (Solana Wallet Adapter) is built on top of the Wallet Standard, both of which are maintained by Anza, a Solana focused dev shop stemming from Solana Labs. This is the most widely used solution in the Solana ecosystem to connect dApps -> Wallets, so we encourage teams to consider using SWA. You get plenty of UI customization options, while ensuring your app can connect to all major Solana wallets.
Note:
If you implement Solana Wallet Adapter on your app, Magic Eden Wallet should work out of the box.
Let's dive into a quick React demo.
Install
Install the adapter specific dependencies
Guide
Create a SolanaProvider Component
Create a SolanaProvider
component that will wrap your application. The goal of this component is to setup a connection to the Solana blockchain on a given network and communicate with via the specified RPC url.
The component wraps its children with providers that pass down the blockchain connection and wallet context, allowing child components to interact with the Solana blockchain.
We've also gone ahead and created a WalletButton we can import into our Navbar / UI layout from the wallet adapter packages.
You'll notice a custom useCluster
method used in the above snippet. This is just a helper function to specify the desired cluster (devnet, mainnet, etc) + the associated RPC details. Hardcoding this information is also fine. Learn more here: https://solana.com/docs/core/clusters
Wrap your App with the SolanaProvider
Next we are going to wrap our React application with the SolanaProvider
component we created above. It may look something like this
Add the Wallet Button to your UI Layout / Navbar
Finally, add the WalletButton
created in the first step to your UI. It is most common to add to your Navbar, or a UiLayout you can wrap your app in, but theoretically you can place this button wherever you please.
Additional Resources
Feel free to reference the popular create-solana-dapp for full context on how to implement the Solana Wallet Adapter in a functional custom Solana application.
Last updated