This guide explains how to use the new FarcasterWalletConnect component in your mini-fun1 application.
The FarcasterWalletConnect component provides additional wallet connection options beyond the built-in FarCaster wallet integration. It supports:
- MetaMask - Popular browser wallet
- WalletConnect v2 - Connect 300+ wallets via QR code
- Coinbase Wallet - Coinbase's mobile wallet
- Farcaster Wallet - Built-in FarCaster wallet
Add your credentials to .env.local:
# Required for WalletConnect v2
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_project_id_from_walletconnect
# Optional: Enhanced OnchainKit features
NEXT_PUBLIC_ONCHAINKIT_API_KEY=your_api_keyGet WalletConnect Project ID:
- Visit WalletConnect Cloud
- Sign up for a free account
- Create a new project
- Copy the Project ID
The component is already integrated into the main page. Users can click "🔗 Connect External Wallet" to access it.
import FarcasterWalletConnect from "./components/FarcasterWalletConnect";
// In your component
<FarcasterWalletConnect />- Shows connected wallet address
- Allows signing messages for authentication
- Easy disconnect functionality
- MetaMask: Most popular browser wallet
- WalletConnect: Scan QR code with mobile wallet
- Coinbase Wallet: Coinbase's official wallet
- Farcaster: Built-in FarCaster wallet support
The component includes a "Sign Message" feature that:
- Proves wallet ownership
- Can be used for session management
- Provides enhanced security
The component uses CSS classes that you can override:
.wallet-connect-container {
/* Main container styling */
}
.wallet-option {
/* Individual wallet option styling */
}
.connected-wallet {
/* Connected state styling */
}You can extend the component to handle connection events:
// In the component, you can add:
useEffect(() => {
if (address) {
// User connected a wallet
console.log('Wallet connected:', address);
// Send to your backend for session creation
}
}, [address]);The connected wallet address can be used in your existing game logic:
const { address } = useAccount();
const handleFlipWithExternalWallet = async () => {
if (address) {
// Use the external wallet address
const response = await fetch('/api/flip', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userAddress: address }),
});
// Handle response...
}
};Your app now supports two types of wallet connections:
-
FarCaster Native Wallet (built-in)
- Automatic connection via context
- No setup required
- Perfect for FarCaster users
-
External Wallets (via FarcasterWalletConnect)
- User choice of wallet
- Manual connection
- More flexibility for advanced users
The connected wallet address can replace or complement the FarCaster wallet address in your API calls:
// Using external wallet
const userAddress = externalWalletAddress || farcasterWalletAddress;
// Send to your flip API
const response = await fetch('/api/flip', {
method: 'POST',
body: JSON.stringify({ userAddress }),
});- Message Signing: Always verify signed messages on your backend
- Session Management: Create sessions based on wallet address + signature
- Rate Limiting: Apply rate limits per wallet address
- Validation: Validate addresses before processing
-
WalletConnect not working
- Check if
NEXT_PUBLIC_WALLETCONNECT_PROJECT_IDis set - Ensure project ID is valid
- Check if
-
MetaMask not appearing
- Make sure MetaMask is installed
- Check browser console for errors
-
Styling issues
- Verify CSS classes are properly imported
- Check for conflicts with existing styles
Add this to see connection details:
const { address, isConnected } = useAccount();
console.log('Wallet State:', { address, isConnected });✅ Enhanced User Choice - Users can use their preferred wallet ✅ Better Adoption - Supports popular wallets like MetaMask ✅ Cross-Platform - WalletConnect enables mobile wallet support ✅ Security - Message signing for authentication ✅ Seamless Integration - Works alongside existing FarCaster integration
- Test with different wallets
- Implement backend signature verification
- Add wallet-specific features
- Consider wallet connection analytics
- Add wallet switching functionality
Ready to enhance your mini app with multiple wallet support! 🎉