A complete example implementation of @farcaster/miniapp-wagmi-connector that demonstrates secure wallet interactions within Farcaster Mini Apps. This example shows how to properly integrate Ethereum wallet functionality without complex wallet selection dialogs or connection issues.
- β Automatic Wallet Connection: No "select your wallet" dialogs needed
- β Single Transactions: Send ETH with user confirmation preview
- β Batch Transactions (EIP-5792): Multiple operations in one confirmation
- β Token Operations: Approve and transfer ERC-20 tokens
- β Security: All transactions scanned and previewed for users
- β Error Handling: Proper error states and user feedback
- β TypeScript: Full type safety throughout the integration
This example uses the official Farcaster Mini App stack:
- @farcaster/miniapp-sdk - Core Mini App functionality
- @farcaster/miniapp-wagmi-connector - Wagmi integration for wallets
- Wagmi - React hooks for Ethereum interactions
- Viem - TypeScript interface for Ethereum
- Node.js 22.11.0 or higher
- A Farcaster account for testing
-
Clone the repository
git clone https://github.com/jumpboxtech/farcaster-miniapp-wagmi-connector cd farcaster-miniapp-wagmi-connector -
Install dependencies
npm install # or pnpm install # or yarn install
-
Start development server
npm run dev
-
Test in Farcaster
During development, you'll need to expose your local server:
# Using ngrok (recommended) npx ngrok http 5173Then use the ngrok URL in the Farcaster Mini App Preview Tool.
βββ src/
β βββ App.tsx # Main app component with providers
β βββ FarcasterWalletDemo.tsx # Core wallet demo component
β βββ EnhancedSecurityWalletDemo.tsx # Enhanced security version
β βββ wagmi.config.ts # Wagmi configuration
β βββ main.tsx # Entry point
βββ public/
β βββ .well-known/
β βββ farcaster.json # Mini App manifest (for production)
βββ package.json
This repository includes two versions of the wallet demo:
- Basic Version (
FarcasterWalletDemo.tsx) - Clean, simple, and secure implementation - Enhanced Security Version (
EnhancedSecurityWalletDemo.tsx) - Additional security features including input validation, rate limiting, and enhanced error handling
To use the enhanced version instead of the basic one, you would update your App.tsx:
// Replace this line:
import { FarcasterWalletDemo } from './FarcasterWalletDemo';
// With this:
import { EnhancedSecurityWalletDemo } from './EnhancedSecurityWalletDemo';
// And update the component in the JSX:
<EnhancedSecurityWalletDemo />- β Input Validation: Address format validation and amount bounds checking
- β Rate Limiting: 5-second cooldown between transactions to prevent spam
- β Safety Limits: Maximum transaction amounts and minimum thresholds
- β Enhanced Error Handling: Specific error messages and real-time feedback
- β Input Sanitization: Automatic address formatting and validation
The key to Farcaster Mini App wallet integration is using the official connector:
import { http, createConfig } from 'wagmi';
import { base } from 'wagmi/chains';
import { farcasterMiniApp as miniAppConnector } from '@farcaster/miniapp-wagmi-connector';
export const config = createConfig({
chains: [base],
transports: {
[base.id]: http(),
},
connectors: [
miniAppConnector() // This handles Farcaster wallet connections
]
});import { WagmiProvider } from 'wagmi';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
const queryClient = new QueryClient();
export const App = () => (
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
<YourAppContent />
</QueryClientProvider>
</WagmiProvider>
);import { sdk } from '@farcaster/miniapp-sdk';
useEffect(() => {
const initializeApp = async () => {
// This hides the splash screen and shows your app
await sdk.actions.ready();
};
initializeApp();
}, []);import { useAccount, useConnect } from 'wagmi';
const { isConnected, address } = useAccount();
const { connect, connectors } = useConnect();
// Auto-connect or manual connection
const handleConnect = () => {
if (connectors[0]) {
connect({ connector: connectors[0] });
}
};Single Transaction:
import { useSendTransaction } from 'wagmi';
import { parseEther } from 'viem';
const { sendTransaction } = useSendTransaction();
const sendEth = () => {
sendTransaction({
to: '0x...',
value: parseEther('0.01')
});
};Batch Transactions (EIP-5792):
import { useSendCalls } from 'wagmi';
const { sendCalls } = useSendCalls();
const batchTransactions = () => {
sendCalls({
calls: [
{ to: '0x...', value: parseEther('0.01') },
{ to: '0x...', value: parseEther('0.02') }
]
});
};- Transaction Scanning: All transactions are automatically scanned by Blockaid
- User Confirmation: Users see detailed previews before confirming
- No Private Keys: Your app never handles private keys directly
- Secure Connection: Built-in protection against common Web3 vulnerabilities
- Local Development: Use ngrok to expose your local server
- Preview Tool: Test using Farcaster's preview tool
- Live Testing: Share your app in Farcaster to test the full user experience
| Feature | Status | Description |
|---|---|---|
| β Wallet Connection | Supported | Automatic connection without wallet selection |
| β Send ETH | Supported | Basic ETH transfers with confirmation |
| β Batch Transactions | Supported | Multiple operations in single confirmation |
| β ERC-20 Operations | Supported | Token transfers, approvals, etc. |
| β Multi-chain | Supported | Base, Mainnet, Optimism, Arbitrum, Polygon |
| β Transaction Status | Supported | Real-time status tracking |
| β Error Handling | Supported | Comprehensive error states |
- Base (recommended for Farcaster apps)
- Ethereum Mainnet
- Optimism
- Arbitrum
- Polygon
Q: Why do I see an infinite loading screen?
A: Make sure you're calling sdk.actions.ready() after your app loads.
Q: Can I use this with other wallet libraries?
A: While possible, we recommend sticking with Wagmi + the official connector for the best experience.
Q: How do I test batch transactions?
A: The demo includes working examples. Batch transactions are supported on all EVM chains.
Q: What about transaction failures?
A: The example includes comprehensive error handling for failed transactions.
Make sure you're using Node.js 22.11.0 or higher:
node --versionDuring development with ngrok/localtunnel:
- Visit the tunnel URL directly in your browser first
- Then use it in the Farcaster preview tool
- Some SDK actions like
addMiniApp()won't work with tunnel domains
For production, you'll need:
- A proper domain (not a tunnel URL)
- HTTPS enabled
- A manifest file at
/.well-known/farcaster.json
- Farcaster Mini Apps Documentation
- miniapp-wagmi-connector NPM Package
- Wagmi Documentation
- Viem Documentation
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ for the Farcaster ecosystem