This is a Next.js starter kit to bootstrap your Farcaster Mini App
- Install dependencies:
npm install
# or
yarn install
# or
pnpm install
# or
bun install- Verify environment variables:
The environment variables enable the following features:
- Frame metadata - Sets up the Frame Embed that will be shown when you cast your frame
- Account association - Allows users to add your frame to their account, enables notifications
- Redis API keys - Enable Webhooks and background notifications for your application by storing users notification details
# Required for Frame metadata
NEXT_PUBLIC_URL=
# Required to allow users to add your frame
NEXT_PUBLIC_FARCASTER_HEADER=
NEXT_PUBLIC_FARCASTER_PAYLOAD=
NEXT_PUBLIC_FARCASTER_SIGNATURE=
# Optional: Set to "production" to disable Eruda debugger
NEXT_PUBLIC_APP_ENV=development
# Required for user authentication
NEYNAR_API_KEY=
JWT_SECRET=
# Required for webhooks and background notifications
REDIS_URL=
REDIS_TOKEN=- Start the development server:
npm run dev- Run a local tunneling server
- Generate your Farcaster Manifest variables
- Follow these instructions
- Visit Manifest Tool
- Paste your tunnel domain
The app uses a layered provider architecture in components/providers/index.tsx:
- EnvironmentProvider - Detects if the app is running in a browser or Farcaster Mini App context
- ErudaProvider - Mobile debugging console (disabled in production via
NEXT_PUBLIC_APP_ENV) - WagmiProvider - Wallet connection with Farcaster Mini App connector and Coinbase Wallet support
- QueryClientProvider - React Query for data fetching
- FarcasterProvider - Mini App SDK initialization, context, and safe area insets
- UserProvider - User authentication state with auto sign-in support
Three custom context hooks are available:
useEnvironment()- AccessisInBrowser,isInFarcasterMiniApp, andisLoadingstatesuseFarcaster()- Access Mini App context, capabilities, safe area insets, and SDK stateuseUser()- Access user data, sign-in methods, and authentication state
JWT-based authentication using Farcaster Quick Auth:
- Sign-in flow - Uses
@farcaster/quick-authto verify user identity - API routes -
/api/auth/sign-infor authentication,/api/auth/checkfor session validation - User data -
/api/users/mereturns authenticated user profile from Neynar - Auto sign-in - Configurable automatic authentication when Mini App loads
Custom hooks for API interactions built on React Query:
useApiQuery- For GET requests with caching, protected routes supportuseApiMutation- For POST/PUT/DELETE requests with optimistic updates
.well-known/farcaster.jsonendpoint configured for Frame metadata and account association- Frame metadata automatically added to page headers in
layout.tsx
- Redis-backed notification system using Upstash
- Ready-to-use notification endpoints in
api/notifyandapi/webhook - Notification client utilities in
lib/notification-client.ts
When accessed from a regular browser (not in Farcaster/Base), the app displays a landing page with:
- QR code for easy mobile access
- Direct launch buttons for Farcaster and Base (Coinbase Wallet)
- App information and branding
Pre-configured Wagmi setup with:
- Farcaster Mini App connector (
@farcaster/miniapp-wagmi-connector) - Coinbase Wallet connector
- Base and Mainnet chain support
dynamic-image-example/[id]/page.tsxshows how to create a Mini App URL resolving to a custom preview imageapi/og/example/[id]/route.tsxshows how to generate a custom preview image usingnext/og- Utility functions in
lib/og-utils.tsfor loading Google Fonts and images
- Eruda - Mobile debugging console, automatically disabled in production
- Type-safe environment variables - Using
@t3-oss/env-nextjswith Zod validation - Secure headers - CSP and security headers configured via
next-secure-headers
├── app/
│ ├── api/
│ │ ├── auth/ # Authentication endpoints
│ │ ├── notify/ # Push notification endpoints
│ │ ├── og/ # Dynamic OG image generation
│ │ ├── users/ # User data endpoints
│ │ └── webhook/ # Webhook handlers
│ └── dynamic-image-example/ # Dynamic preview image example
├── components/
│ ├── pages/ # Page components (home, website)
│ ├── providers/ # Context providers
│ └── shared/ # Reusable UI components
├── contexts/ # React contexts
├── hooks/ # Custom React hooks
└── lib/ # Utilities and configurations