Skip to content

JSONbored/flip-battle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

48 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿช™ Flip Battle

Provably Fair Coin Flip Betting on Base

Challenge anyone to a coin flip duel. Bet USDC, earn rewards, build streaks. All powered by Chainlink VRF on Base network.


๐ŸŽฏ Project Status

Current Version: v0.1.0 (Testnet Ready) Phase: 15/17 Complete (87%) Build Status: โœ… Passing Test Coverage: 70/70 tests passing

Ready for: Base Sepolia deployment Next: Testnet testing โ†’ Mainnet deployment


โœจ Features

Core Features

  • ๐ŸŽฒ Coin Flip Betting - Challenge any address, 1+ USDC bets, provably fair
  • ๐Ÿ”ฅ Daily Streaks - Check in daily, earn up to 150 USDC at milestones
  • ๐Ÿ‘ฅ Referral System - 1 USDC signup bonus + 5% of all referral bets
  • ๐ŸŽ Daily Free Flip - Free flip every 24 hours, funded by platform fees

Engagement

  • ๐Ÿ“Š Statistics - Track games, wins, profit, win rate
  • ๐Ÿ† Achievements - 6 achievement tiers to unlock
  • ๐Ÿ”” Live Events - Real-time event feed and notifications
  • ๐ŸŽญ Farcaster - Profile display, sharing, auto-cast

Technical

  • โšก Fast - ~30-60s VRF fulfillment
  • ๐Ÿ”’ Secure - OpenZeppelin security standards
  • ๐Ÿ’ฐ Fair - 95% payout, 5% platform fee
  • ๐Ÿ“ฑ Mobile - Fully responsive design

๐Ÿ—๏ธ Tech Stack

Smart Contracts

  • Solidity 0.8.28
  • Foundry (forge, cast, anvil)
  • Chainlink VRF v2.5 (provable randomness)
  • OpenZeppelin (security standards)
  • Base Network (Ethereum L2)

Frontend

  • Next.js 15.5.4 (App Router)
  • React 19.1.1
  • TypeScript 5.9.3 (strict mode)
  • TailwindCSS 4.1.13
  • Framer Motion 12.23.22
  • wagmi 2.17.5 + viem 2.37.9
  • Reown AppKit 1.8.8 (WalletConnect)
  • Neynar SDK 3.34.0 (Farcaster)

Infrastructure

  • Turborepo 2.5.8 (monorepo)
  • Vercel (deployment)
  • BaseScan (verification)

๐Ÿ“ Project Structure

flip-battle/
โ”œโ”€โ”€ contracts/                    # Smart contracts (Foundry)
โ”‚   โ”œโ”€โ”€ src/                      # Contract source files
โ”‚   โ”‚   โ”œโ”€โ”€ FlipBattle.sol        # Core betting logic
โ”‚   โ”‚   โ”œโ”€โ”€ StreakManager.sol     # Daily streaks
โ”‚   โ”‚   โ”œโ”€โ”€ ReferralSystem.sol    # Referral tracking
โ”‚   โ”‚   โ””โ”€โ”€ DailyFreeFlip.sol     # Free daily flip
โ”‚   โ”œโ”€โ”€ test/                     # 70 tests (all passing)
โ”‚   โ”œโ”€โ”€ script/                   # Deployment scripts
โ”‚   โ”‚   โ”œโ”€โ”€ Deploy.s.sol          # Main deployment
โ”‚   โ”‚   โ””โ”€โ”€ DeployLocal.s.sol     # Local testing
โ”‚   โ”œโ”€โ”€ deploy-sepolia.sh         # Interactive deployment
โ”‚   โ”œโ”€โ”€ test-contracts.sh         # Contract testing tool
โ”‚   โ””โ”€โ”€ foundry.toml              # Foundry config
โ”‚
โ”œโ”€โ”€ apps/web/                     # Next.js frontend
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ components/           # 13 React components
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/                # 28 custom hooks
โ”‚   โ”‚   โ”œโ”€โ”€ lib/                  # Config & utilities
โ”‚   โ”‚   โ”œโ”€โ”€ games/                # Games list page
โ”‚   โ”‚   โ”œโ”€โ”€ profile/              # Profile page
โ”‚   โ”‚   โ””โ”€โ”€ page.tsx              # Home page
โ”‚   โ”œโ”€โ”€ public/
โ”‚   โ”‚   โ””โ”€โ”€ .well-known/
โ”‚   โ”‚       โ””โ”€โ”€ farcaster.json    # Mini app manifest
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ”œโ”€โ”€ DEPLOYMENT_CHECKLIST.md       # Step-by-step deployment
โ”œโ”€โ”€ VERCEL_DEPLOYMENT.md          # Vercel-specific guide
โ”œโ”€โ”€ TESTING_GUIDE.md              # Test scenarios
โ”œโ”€โ”€ TEST_USDC_GUIDE.md            # Get testnet USDC
โ”œโ”€โ”€ PROJECT_STATUS.md             # Current status
โ””โ”€โ”€ README.md                     # This file

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+ or Bun 1.2+
  • Foundry (for contracts)
  • Git

Installation

# Clone repository
git clone https://github.com/yourusername/flip-battle.git
cd flip-battle

# Install dependencies
bun install

# Build everything
bun run build

Local Development

Frontend:

cd apps/web
bun run dev
# Open http://localhost:3000

Contracts:

cd contracts

# Run tests
forge test

# Local deployment (Anvil)
make deploy-local

๐Ÿ“ฆ Deployment

Base Sepolia Testnet

See: DEPLOYMENT_CHECKLIST.md for complete step-by-step guide

Quick version:

  1. Get Prerequisites:

    • Base Sepolia ETH (0.1+ ETH)
    • VRF subscription (2+ LINK)
    • BaseScan API key
    • WalletConnect Project ID
  2. Deploy Contracts:

    cd contracts
    ./deploy-sepolia.sh
  3. Add VRF Consumers at https://vrf.chain.link

  4. Update Vercel Env Vars with contract addresses

  5. Deploy Frontend:

    cd apps/web
    vercel --prod
  6. Test Everything - See TESTING_GUIDE.md


๐Ÿ“Š Smart Contracts

FlipBattle.sol

Core coin flip betting contract with Chainlink VRF integration.

Key Functions:

  • createFlip(opponent, amount, choice) - Create challenge
  • acceptFlip(gameId) - Accept challenge
  • cancelFlip(gameId) - Cancel before acceptance
  • claimWinnings(gameId) - Claim prize after win

Events:

  • FlipCreated, FlipAccepted, FlipResolved, FlipCancelled

StreakManager.sol

Daily check-in system with milestone rewards.

Milestones:

  • Day 7: 5 USDC
  • Day 14: 12 USDC
  • Day 30: 30 USDC
  • Day 60: 75 USDC
  • Day 90: 150 USDC

ReferralSystem.sol

Referral tracking and earnings.

Rewards:

  • 1 USDC signup bonus
  • 5% of all referral bets

DailyFreeFlip.sol

Free daily flip lottery funded by platform fees.

Details:

  • Free entry (only gas)
  • 2% of platform fees go to prize pool
  • One play per 24 hours

๐Ÿงช Testing

Smart Contracts

cd contracts

# Run all tests
forge test

# With gas report
forge test --gas-report

# Specific test
forge test --match-test testCreateFlip -vvv

Status: 70/70 tests passing โœ…

Frontend

cd apps/web

# Build
bun run build

# Type check
bun run type-check

# Lint
bun run lint

Status: Build passing โœ…


๐Ÿ“– Documentation


๐ŸŽฎ How to Play

  1. Connect Wallet via WalletConnect
  2. Get USDC (testnet or mainnet)
  3. Create Challenge:
    • Enter opponent address
    • Choose bet amount (1+ USDC)
    • Select Heads or Tails
  4. Wait for Acceptance or accept pending challenges
  5. Coin Flip - Chainlink VRF determines winner in ~60s
  6. Winner Claims - 95% of pot goes to winner

Bonus Features:

  • Daily check-ins for streak rewards
  • Refer friends for bonuses
  • Free daily flip lottery

๐ŸŽฏ Roadmap

โœ… Phase 1-15 Complete (87%)

  • Smart contract development
  • Frontend development
  • Testing & documentation
  • Deployment scripts

๐Ÿšง Current: Phase 16-17

  • Testnet deployment
  • Testing & bug fixes
  • Mainnet preparation
  • Launch! ๐Ÿš€

๐Ÿ”ฎ Future Features

  • Multiplayer tournaments
  • NFT rewards for achievements
  • DAO governance
  • Mobile app

๐Ÿ’ฐ Economics

Platform Fees

  • 5% of all flip bets
  • 2% to daily free flip prize pool
  • 3% to operations and rewards

Reward Pools

  • Streaks: Pre-funded reward pool
  • Referrals: Paid from platform fees
  • Daily Free Flip: Funded by 2% of fees

๐Ÿ”’ Security

  • OpenZeppelin contracts for security standards
  • Chainlink VRF for provable randomness
  • ReentrancyGuard on all state-changing functions
  • 70 unit tests covering all functionality
  • Recommended: Security audit before mainnet

๐Ÿ“ž Support & Links

Documentation

External Resources

Quick Commands

# Deploy contracts
cd contracts && ./deploy-sepolia.sh

# Test contracts
cd contracts && forge test

# Build frontend
cd apps/web && bun run build

# Deploy frontend
vercel --prod

๐Ÿค Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests: forge test and bun run build
  5. Submit a pull request

๐Ÿ“„ License

MIT License - see LICENSE file for details


๐ŸŽ‰ Acknowledgments

Built with:

  • Base - Ethereum L2 network
  • Chainlink - VRF randomness
  • WalletConnect - Wallet connections
  • Farcaster - Social integration
  • Vercel - Hosting platform

Ready to flip? ๐Ÿช™

See DEPLOYMENT_CHECKLIST.md to get started!

About

Flip Battle is a Farcaster Mini App on the Base L2 blockchain network, utilizing WalletConnect

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •