Solana Wallet Adapter
Last updated
Last updated
The is built on top of the , both of which are maintained by , 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.
Let's dive into a quick React demo.
Install the adapter specific dependencies
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.
Next we are going to wrap our React application with the SolanaProvider
component we created above. It may look something like this
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.
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:
Feel free to reference the popular for full context on how to implement the Solana Wallet Adapter in a functional custom Solana application.