🔍 An AI-powered social deduction game on Farcaster
Can you tell if you're chatting with a real person or an AI bot trained on their posts?
The documentation has been consolidated into 6 comprehensive guides covering all aspects of the Detective project:
- HACKATHON_SUBMISSION.md - Read this first for Arbitrum Buildathon judging criteria and technical highlights.
- CORE_ARCHITECTURE.md - System architecture, advanced features, and scaling guide
- GAME_DESIGN_UIUX.md - Game mechanics, UI/UX enhancements, and user experience design
- IMPLEMENTATION_ADVANCED.md - WebSocket implementation, progress log, and advanced features
- ACCESS_CONTROL_SECURITY.md - Access control strategy, security features, and deployment scenarios
- CONTRACT_DEPLOYMENT.md - Smart contract deployment, verification, and operational procedures
- High-level system design and technology stack
- Game mechanics and bot intelligence
- Advanced features: Crypto-Native Agent Auth, Wallet-Linked Identity, Adversarial Metrics, Agent Leaderboard
- Development phases (MVP → production)
- Scaling from single server to horizontal architecture
- Performance optimization and cost analysis
- Game flow with blockchain integration
- UI/UX enhancement (gradients, animations, VoteToggle)
- Homepage redesign and opponent reveal flow
- Mobile-first responsive design principles
- Visual consistency and accessibility
- WebSocket vs HTTP polling analysis
- Ably WebSocket implementation with feature flags
- Core principles compliance (enhancement first, aggressive consolidation)
- Development progress and current status
- Long-term roadmap and ecosystem vision
- Multi-chain access requirements (Arbitrum NFT, Monad token, whitelist)
- Quick activation scripts and configuration
- Security features and edge case handling
- Monitoring, analytics, and community communication
- Implementation timeline and deployment scenarios
- Smart contract deployment on Arbitrum
- Verification procedures and operational guidelines
- Configuration and integration steps
- Emergency procedures and maintenance
Detective is a Farcaster-native social deduction game where players chat with opponents and determine: Human or AI? Built on multi-chain infrastructure (Arbitrum + Monad) with synthetic identity as a core primitive. As AI models become indistinguishable from human behavior, Detective makes detection skills playable, measurable, and economically valuable.
Current Status: Phase 1-4 (Complete) ✅ Multi-Chain Integration & Access Gating Prep
Status: Production Ready with Gating Implementation
Build: ✅ Passing (Next.js 15.5.6, TypeScript strict)
Latest: Farcaster SDK integration, multi-chain leaderboards, access gating preparation
- Node.js 18+ (LTS recommended)
- npm/yarn/pnpm
- API keys:
-
Clone and install:
git clone https://github.com/thisyearnofear/detective.git cd detective npm install -
Configure environment:
cp .env.example .env.local
Then add your API keys to
.env.local:NEYNAR_API_KEY=your_key_here ANTHROPIC_API_KEY=your_key_here JWT_SECRET=your_secret_key VERCEL_URL=localhost:3000 # or your production domain -
Run locally:
npm run dev # Visit http://localhost:3000 -
Build for production:
npm run build npm start
-
Enable pre-commit secret scanning:
git config core.hooksPath .githooks
This blocks commits when staged changes contain likely secrets. If needed, bypass once with:
git commit --no-verify
- Frontend: Next.js 15 + React 19 + TypeScript + Tailwind CSS
- Backend: Next.js API Routes (serverless)
- Mini App SDK:
@farcaster/miniapp-sdkv0.2.1 - Farcaster-native integration - Authentication: Farcaster Quick Auth (2025 standard) - Edge-deployed JWT tokens
- Game State: In-memory (no database required for MVP)
- APIs: Neynar (Farcaster data), Claude (bot intelligence)
- Hosting: Vercel (free tier)
- Manifest:
/public/.well-known/farcaster.json- Farcaster app metadata - SDK Ready:
sdk.actions.ready()called in Providers on app load - Mobile: Viewport/meta tags configured for Farcaster clients
- Authentication: Integrated with Mini App SDK + Quick Auth
Registration (Neynar score > 0.8)
↓
Match Assignment (Real player or bot)
↓
4-minute Chat (HTTP polling)
↓
Voting (Real or Bot?)
↓
Scoring & Leaderboard
↓
Repeat 5 times per game cycle
Detective is fully configured to run as a Farcaster Mini App:
- Manifest Configuration -
/public/.well-known/farcaster.jsondefines app metadata for Farcaster - SDK Integration -
@farcaster/miniapp-sdkhandles native features (auth, wallet, notifications) - Ready Signal -
sdk.actions.ready()called on app load to dismiss splash screen - Mobile Optimization - Viewport settings and meta tags for Farcaster clients
- Authentication - Quick Auth integrated with Mini App environment
To deploy: Push to public HTTPS URL (Vercel recommended), then share your domain with Farcaster. The manifest will be automatically discovered at https://your-domain.com/.well-known/farcaster.json.
- ✅ Realistic Typing Delays: 2-7s thinking time (personality-dependent)
- ✅ Personality-Aware Responses: System prompt now uses all 20+ extracted traits
- ✅ Opening Move Variance: Each bot greets distinctly (frequency-weighted)
- ✅ Authentic Fallbacks: 100% from cast history, intelligent combining
- ✅ Cross-Round Memory: Lite Redis-backed context (topics, player style, phrases)
- ✅ Production-Ready: All required services (Redis, Database, APIs) are mandatory with fail-fast startup
- ✅ Smart Contract:
DetectiveGameEntry.soldeployed on Arbitrum One- Address:
0x2d0B651fE940f965AE239Ec6cF6EA35F502394ff - Verified: Blockscout | Sourcify
- Features: registerForGame(), transferAdmin(), setPaused(), setMinEntryFee()
- Events: PlayerRegistered, AdminTransferred, PauseStatusChanged, MinEntryFeeUpdated
- Errors: ContractPaused, InvalidAddress
- Address:
- ✅ TX Verification:
arbitrumVerification.ts- DRY single source of truth (~300 LOC) - ✅ Registration Flow: Enhanced BriefingRoom with
useRegistrationFlowhook for step progression - ✅ Modal States: idle → wallet-check → signing → confirming → success/error with recovery
- ✅ Feature Gating:
NEXT_PUBLIC_ARBITRUM_ENABLEDfor gradual rollout - ✅ Configuration:
.env.examplewith contract address + verification links - ✅ Sybil Resistance: One-shot registration per wallet per cycle (on-chain proof)
- ✅ Traction Measurement: Entry TX count recorded in smart contract events
Contract ABI: src/lib/detectiveGameEntryAbi.ts with full TypeScript interfaces
Core Principles Applied: ENHANCEMENT FIRST, DRY, CLEAN separation, MODULAR design
See ARCHITECTURE.md - Phase 3A for details.
- ✅ Quick Auth Implementation: Edge-deployed JWT tokens (0 manual nonce management)
- ✅ Simplified Auth Flow: 2-step process (down from 4 steps)
- ✅ Auto-Approval in MiniApp: Works seamlessly in Warpcast context
- ✅ Web QR Support: Automatic QR code for web users
- ✅ Dependency Cleanup: Removed 26 wallet packages (85% reduction)
- ✅ Performance: 73% faster build time, zero Web3 bloat
- ✅ Real Farcaster SDK Integration: Authentic miniapp experience with notifications
- ✅ Multi-Platform Wallet Connection: MetaMask, WalletConnect, Farcaster SDK
- ✅ Registration Lobby System: Real-time player tracking, countdown timers, game start ceremony
- ✅ Bot Response Optimization: Now with realistic delays + personality variance
- ✅ Multi-Chain Leaderboards: Arbitrum (NFT focus) + Monad (token focus) ranking system
- ✅ Mobile-First Design: Touch-optimized UI for Farcaster mobile clients
- ✅ Access Gating Preparation: Token/NFT verification infrastructure
- ✅ Canvas-based animated backgrounds, SVG progress timers
- ✅ OpponentCard with color extraction, registration animations
- ✅ Smooth transitions, error handling, results tracking
Delivered: 25+ new components, real-time features, multi-chain support, mobile optimization
See UI_UX_ROADMAP.md for detailed specs.
- Users must have Neynar score > 0.8 (filters bots/low-quality accounts)
- Hard cap: 50 players per cycle
- System scrapes 30 recent casts per user for bot training
- Duration: 4 minutes per match
- 5 matches per player per cycle
- 50% real users, 50% bots in random assignment
- Messages exchanged via HTTP polling (3s interval)
- Claude 3.5 Sonnet fine-tuned with user's recent posts
- System prompt injects: username, display name, recent casts, tone & style
- Instruction to stay under 240 chars (Farcaster limit)
- After each match: Guess "Real" or "Bot"
- Accuracy calculated per user: (Correct Guesses / Total Guesses) × 100
- Leaderboard sorted by accuracy and speed (tiebreaker)
Per game cycle (50 players, 5 rounds = 250 bot responses):
- Neynar API: Free tier (10k req/day limit, we use ~200)
- Claude API: ~$0.75 (250 responses × $0.003/response)
- Vercel: Free tier
- Total: <$1 per game
Budget estimate: $50-100/month for 10 games (assuming weekly cycles)
Detective uses Farcaster Quick Auth - an official Farcaster edge-deployed service built on Sign In with Farcaster (SIWF).
Key Features:
- Auto-approval in Farcaster clients: Works in Warpcast and other clients without user friction
- QR Code on Web: Automatic QR code generation for web users
- Local JWT Verification: Asymmetrically signed tokens - no API calls needed to verify
- No API Key Required: Farcaster service is public, verification uses cryptographic signatures only
- Token Claims:
{ sub: fid, iat, exp, aud: domain, iss: "https://auth.farcaster.xyz" }
Implementation:
// Client - No API key needed
import QuickAuthComponent from '@/components/QuickAuthComponent';
<QuickAuthComponent onAuthSuccess={(user, token) => {...}} />
// Server - Verify JWT locally using public key cryptography
import { verifyQuickAuthToken } from '@/lib/quickAuthUtils';
const payload = await verifyQuickAuthToken(token, hostname);
const fid = payload.sub; // User's Farcaster IDFiles:
src/lib/quickAuthUtils.ts- JWT verification utilities (no secret key needed)src/components/QuickAuthComponent.tsx- Auth UI componentsrc/app/api/auth/quick-auth/verify/route.ts- Verification endpoint
Docs: See Farcaster Quick Auth
GET /api/game/status- Consolidated game state, phase info, and player listPOST /api/game/register- Register user for game cyclePOST /api/game/ready- Signal player readiness
GET /api/match/active- Get active matches for a playerPOST /api/chat/send- Send message (relay or generate bot response)POST /api/match/vote- Submit or update vote (POST) / Lock vote (PUT)
GET /api/leaderboard/current- Current game rankingsGET /api/leaderboard/multi-chain- Multi-chain rankings (Arbitrum/Monad)GET /api/leaderboard/agents- Agent Arena DSR rankingsGET /api/leaderboard/insights- Personal performance insightsGET /api/leaderboard/game/[cycleId]- Historical game resultsGET /api/stats/career- Career stats and game history
POST /api/auth/quick-auth/verify- Verify Quick Auth JWT token
Contributions welcome! Please:
- Fork the repo
- Create a feature branch (
git checkout -b feature/amazing-thing) - Commit your changes (
git commit -am 'Add amazing thing') - Push to the branch (
git push origin feature/amazing-thing) - Open a Pull Request
MIT License - see LICENSE.md
- 🐛 Bugs: Open an issue
- 💬 Questions: Tweet @stefanbohacek or mention @detective
- 📊 Farcaster: Join the Detective channel
For production integration of new components:
- ErrorCard - Add to API error handlers for network failures
- RoundTransition - Trigger when switching between rounds
- ResultsCard - Show when votes are revealed with accuracy stats
- RoundStartLoader - Display while finding opponents
See UI_UX_ROADMAP.md for component API reference and integration examples.
Built for Farcaster. Made with ❤️