Adding Eclipse Wallet to dApp
You will need a wallet that is compatible with Eclipse because the SVM RPC pulls a recent block hash from whichever RPC you're connected to.
Adding MetaMask Snap To Your dApp
To support MetaMask, we recommend adding Drift's MetaMask Snap to your dApp by following their instructions. First, install the npm package: npm install --save @drift-labs/snap-wallet-adapter
Then in index.tsx:
Adding Salmon Wallet To Your dApp
The Solana wallet provider automatically identifies the Salmon wallet if it is installed for users, so your SVM dApp requires no additional changes to support Salmon.
Custom Wallet Support for Solana Wallet Adapter
For a better user experience, customize the Solana wallet adapter to only show Eclipse-compatible wallets.
Prerequisites
As Solana wallet adapter is a JS/TS specific library, we need to initialize a project with a preferred framework. Let's create an example application using next:
Next, install the wallet adapter library:
Initializing Wallets
Start by editing your _app.tsx
file located inside the src
folder or the app
folder depending on how you have set up the next.js app. Include the required libraries in the _app.tsx
file. Here you can use the adapter for Salmon wallet and MetaMask Snap:
Now, initialize the allowed wallets in your _app.tsx
file. You can set the network and add the Eclipse RPC:
You have used the @solana/wallet-adapter-react
to set up the connection with Eclipse compatible wallets.
Filtering Wallets
When a user has multiple wallets installed in their browser, each of the wallets will have a readyState value set to "Installed". This causes wallets incompatible with Eclipse to be autodetected. This can be fixed by whitelisting only the supported wallets. To do this, we must first create a new component. You can name this wallets.tsx
.
Here is an array of supported wallets, which makes adding support for wallets more modular. Once you modify the _app.tsx
, just add the Eclipse compatible wallet to the array.
The last step is to map the supported wallets and render them as buttons. Since MetaMask Snap does not return a readyState value, you must add an exception for it so that it displays regardless of the readyState.
This will allow us to 1) restrict the user to only use Eclipse compatible wallets and 2) restrict the dApp to only detect supported wallets that are installed. Finally, you can export the component and add it to your index.tsx
file.
Here is an example web application styled using DaisyUI:
Last updated