Interacting with Solana wallets
Mini Apps can interact with a user's Solana wallet without needing to worry about popping open "select your wallet" dialogs or flakey connections.
Getting Started
The SDK enables Mini Apps to interact with a user's Solana wallet through Wallet Standard.
We recommend using Wallet Adapter's React hooks to interface with Wallet Standard. You may also use Wallet Standard directly, or interface with our low-level Solana provider.
Setup Wallet Adapter
Use the Quick Setup (using React) guide to setup Wallet Adapter in your project.
Install the Wallet Standard integration
npm install @farcaster/mini-app-solana
Render the Farcaster Solana provider
In place of ConnectionProvider
and WalletProvider
from the Wallet Adapter guide, you should render FarcasterSolanaProvider
from @farcaster/mini-app-solana
.
This does two things:
- Importing from
@farcaster/mini-app-solana
has the side effect of triggering the Farcaster wallet to register via Wallet Standard. - Sets up Wallet Adapter to automatically select the Farcaster wallet.
import * as React from 'react';
import { FarcasterSolanaProvider } from '@farcaster/mini-app-solana';
import { useWallet } from '@solana/wallet-adapter-react';
const solanaEndpoint = 'https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY';
function App() {
// FarcasterSolanaProvider internally renders ConnectionProvider
// and WalletProvider from @solana/wallet-adapter-react
return (
<FarcasterSolanaProvider endpoint={solanaEndpoint}>
<Content />
</FarcasterSolanaProvider>
)
}
Use the Wallet Adapter hooks
You can now use Wallet Adapter React hooks directly within any component rendered downstream of FarcasterSolanaProvider
.
function Content() {
const { publicKey } = useWallet();
const solanaAddress = publicKey?.toBase58() ?? '';
return <span>{solanaAddress}</span>;
}
Low-level Solana provider
The SDK also exposes a low-level Solana provider at sdk.wallet.getSolanaProvider()
.
This provider is modeled after window.phantom.solana
and its full API can be found here.
Using Wallet Standard directly
It's also possible to interface with the user's Solana wallet directly through Wallet Standard, or via Wallet Adapter's "core" (non-React) integrations.
In order to do so, it's important that you still import our package in your app entry:
import '@farcaster/mini-app-solana';
This ensures that the user's Solana wallet registers with Wallet Standard.
Also note that if you're using Wallet Adapter without our FarcasterSolanaProvider
React component, you'll need to select the user's Farcaster wallet before attempting any operations.
Demo app
To see how a working Mini App uses a Solana wallet, check out our demo Mini App here.
Troubleshooting
Transaction Scanning
Modern crypto wallets scan transactions and preview them to users to help protect users from scams. New contracts and applications can generate false positives in these systems. If your transaction is being reported as potentially malicious use this Blockaid Tool to verify your app with Blockaid.