This sprite runner game has been integrated as a Farcaster Mini App with on-chain payment gating for score reveal. Players must pay 0.00001 ETH to see their final score when playing inside the Farcaster environment.
├── farcaster.json # Farcaster Mini App manifest
├── lib/farcaster/
│ ├── wagmi-config.ts # Wagmi configuration for Web3
│ └── farcaster-provider.tsx # Farcaster SDK context provider
├── hooks/
│ └── use-pay-to-reveal.ts # Custom hook for payment logic
└── components/
└── game-over-modal.tsx # Updated with payment gate
- Initializes the Farcaster Frame SDK
- Detects if the app is running inside Farcaster
- Provides SDK context and user info to the entire app
- Signals SDK ready state with
sdk.actions.ready()
- Configures Web3 connections for Base, Mainnet, and Optimism
- Uses HTTP transports for RPC connections
- Provides SSR support for Next.js
- Manages payment state and transaction flow
- Automatically reveals score if not in Farcaster (fallback behavior)
- Handles wallet connection via Farcaster SDK
- Switches to Base network for payments
- Sends 0.00001 ETH transaction to recipient address
- Tracks transaction status and reveals score on confirmation
- Shows payment gate when in Farcaster and score not revealed
- Displays "Connect Wallet" button if wallet not connected
- Shows "Pay to Reveal" button once connected
- Reveals full score stats after successful payment
- Falls back to immediate score display outside Farcaster
- Game Ends: Player finishes their run
- Environment Check: App detects if running in Farcaster Mini App
- Payment Gate: If in Farcaster, score is hidden behind payment
- Wallet Connection: Player connects wallet via Farcaster SDK
- Transaction: Player approves 0.00001 ETH payment on Base network
- Confirmation: Transaction is confirmed on-chain
- Score Reveal: Full stats (score, coins, distance) are displayed
- Leaderboard: Player can submit their score to the leaderboard
The app uses useFarcaster() hook to detect the environment:
isInFarcaster: true if running inside Farcaster Mini AppisSDKLoaded: true when SDK initialization is completecontext: Farcaster frame contextuser: Farcaster user information
When running outside Farcaster (e.g., in a browser):
- Payment gate is automatically bypassed
- Scores are immediately visible
- All game features work normally
- No wallet connection required
In hooks/use-pay-to-reveal.ts, replace the placeholder address:
const RECIPIENT_ADDRESS = '0xYourAddressHere' // Replace with your actual addressIn farcaster.json, update with your actual URLs:
{
"iconUrl": "https://your-domain.com/icon.png",
"splashImageUrl": "https://your-domain.com/splash.png",
"homeUrl": "https://your-domain.com"
}In app/layout.tsx, update the Open Graph image:
'fc:frame:image': 'https://your-domain.com/og-image.png'- Install Dependencies:
npm install- Build for Production:
npm run build-
Deploy to Vercel (or your hosting platform)
-
Register with Farcaster:
- Ensure
farcaster.jsonis accessible at your domain root - Submit your app to Farcaster for Mini App registration
- Test in Farcaster client before public launch
- Ensure
- Run
npm run dev - Game works normally without payment gate
- Scores are immediately visible
- Deploy to a public URL
- Open in Farcaster client
- Test wallet connection flow
- Verify payment transaction on Base testnet first
- Test score reveal after payment
- Transaction Verification: In production, implement server-side verification of transactions
- Network Selection: App automatically switches to Base network for payments
- Error Handling: Comprehensive error messages for failed transactions
- Wallet Security: Uses Farcaster's secure wallet provider
- Server-side transaction verification API
- Database storage for verified payments
- NFT rewards for top scores
- Multi-chain support
- Dynamic pricing based on difficulty
For issues or questions:
- Check Farcaster Frame SDK docs: https://docs.farcaster.xyz/
- Wagmi documentation: https://wagmi.sh/
- Open an issue in the repository