Skip to content

7maylord/colorsnap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

31 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ ColorSnap Game

A Decentralized Multi-Chain Color Matching Game

Watch Demo

ColorSnap Demo

Next.js Solidity TypeScript Tailwind CSS

Play Now Quick Start Features How to Play

Base Status Somnia Status Electroneum Status

GitHub stars GitHub forks GitHub watchers


๐Ÿ“– Overview

ColorSnap is a revolutionary decentralized puzzle game where players match colored bottles to target configurations on the blockchain. Connect your wallet, compete globally, and earn points in this engaging multi-chain experience.

๐ŸŽฎ Interactive Game Preview (Click to expand)
๐Ÿงช Current Game State: [๐Ÿ”ด][๐Ÿ”ต][๐ŸŸข][๐ŸŸก][๐ŸŸฃ]
๐ŸŽฏ Target Pattern:     [๐ŸŸฃ][๐ŸŸข][๐Ÿ”ด][๐Ÿ”ต][๐ŸŸก]

Actions Available:
โ”Œโ”€ ๐Ÿ”„ Swap bottles     โ”Œโ”€ ๐Ÿ‘๏ธ Peek at solution (after 5 moves)
โ”œโ”€ โœ… Submit solution  โ”œโ”€ ๐Ÿšซ Forfeit game  
โ””โ”€ ๐Ÿ“Š Check progress   โ””โ”€ ๐Ÿ† View leaderboard

๐Ÿƒโ€โ™‚๏ธ Try the sequence: Swap(1,5) โ†’ Swap(2,4) โ†’ Swap(1,3) โ†’ Submit!

๐ŸŽฏ Core Gameplay

  • ๐Ÿงช Match colored bottles to hidden target patterns
  • ๐Ÿ”„ Swap bottle positions strategically
  • ๐Ÿ‘๏ธ Peek at solutions after 5 moves (with cooldown)
  • ๐Ÿ† Earn 10 points per completed puzzle
  • ๐Ÿ“Š Compete globally on the leaderboard

๐Ÿ› ๏ธ Technology Stack

Component Technology Version ๐Ÿ“Š Usage
Smart Contracts Solidity + Foundry Latest ๐Ÿ”— Core Logic
Frontend Next.js + TypeScript 15.x ๐ŸŽจ UI/UX
Web3 Integration Wagmi + Reown Latest ๐Ÿ”Œ Web3 Connectivity
Styling Tailwind CSS 3.x ๐Ÿ’… Responsive Design
Default Network Base 8453 โ›“๏ธ Blockchain Layer

๐ŸŒ Deployed Contracts

Our smart contracts are live across multiple networks for maximum accessibility:

๐ŸŒŸ Network ๐Ÿ“ Contract Address ๐Ÿ”— Explorer โ›“๏ธ Chain ID ๐Ÿ“Š Status
๐Ÿ”ต Base Mainnet 0x62dcaAdAd6D5E6CA4B594CEB636A147537aE7F8f
๐Ÿ“‹ Copy Address
BaseScan 8453 ๐ŸŸข LIVE
๐ŸŸก Somnia Testnet 0xc2dc20E9F389114578F78a7f3C3B071db0b8e8dC
๐Ÿ“‹ Copy Address
Somnia Explorer 50312 ๐ŸŸก TESTNET
โšก Electroneum Testnet 0xEF7902FeE12ea3D3245eD721767FB048Afa38a2f
๐Ÿ“‹ Copy Address
Electroneum Explorer 5201420 ๐Ÿ”ต TESTNET
๐Ÿ”„ Quick Network Setup (Click to expand)

Add Networks to MetaMask

Base Mainnet:

Network Name: Base Mainnet
RPC URL: https://mainnet.base.org
Chain ID: 8453
Currency Symbol: ETH
Block Explorer: https://basescan.org

Somnia Testnet:

Network Name: Somnia Testnet  
RPC URL: https://testnet-rpc.somnia.network
Chain ID: 50312
Currency Symbol: ETH
Block Explorer: https://shannon-explorer.somnia.network

Electroneum Testnet:

Network Name: Electroneum Testnet
RPC URL: https://testnet-rpc.electroneum.com  
Chain ID: 5201420
Currency Symbol: ETN
Block Explorer: https://testnet-explorer.electroneum.com
๐ŸฆŠ Add to MetaMask (Manual)

โœจ Features

๐Ÿ”— Wallet Integration

  • Connect any EVM-compatible wallet
  • MetaMask, WalletConnect, and more
  • Seamless multi-chain support

๐Ÿ‘ค Player Registration

  • Set your champion name on-chain
  • Persistent identity across networks
  • Global recognition system

๐ŸŽฎ Interactive Gameplay

  • Intuitive bottle swapping mechanics
  • Real-time visual feedback
  • Strategic peek system with cooldowns

๐Ÿ† Global Competition

  • Live leaderboard updates
  • Cross-network score aggregation
  • Compete with players worldwide

๐Ÿ“ฑ Responsive Design

  • Works on all devices
  • Mobile-optimized interface
  • Smooth animations and transitions

โšก Real-time Updates

  • Live game state monitoring
  • Instant transaction feedback
  • Dynamic UI updates

๐Ÿš€ Quick Start

๐Ÿ“‹ Prerequisites

  • Node.js 18+ and npm/yarn
  • Foundry (for smart contract development)
  • EVM-compatible wallet
  • Testnet ETH for transactions

๐Ÿ”ง Interactive Installation

๐Ÿ“ฆ Step 1: Clone & Setup Repository
# ๐ŸŽฏ Clone the repository
git clone https://github.com/7maylord/colorsnap.git
cd colorsnap

# ๐Ÿ“ Verify project structure
ls -la
# Expected output:
# README.md
# frontend/
# smart-contracts/
โœ… Verification Checkpoint

Run this command to verify your setup:

echo "โœ… Repository cloned successfully!" && \
echo "๐Ÿ“ Current directory: $(pwd)" && \
echo "๐Ÿ“ Files found: $(ls | wc -l) items"
โ›“๏ธ Step 2: Smart Contract Deployment
# Navigate to smart contracts directory
cd smart-contracts

# Install Foundry dependencies
forge install

# Set your environment variables
export RPC_URL="your_rpc_url_here"
export PRIVATE_KEY="your_private_key_here"

# ๐Ÿš€ Deploy the contract
forge script script/Colorsnap.s.sol --rpc-url $RPC_URL --broadcast
๐ŸŒ Network-Specific Deployment Commands

๐Ÿ”ต Base Mainnet:

forge script script/Colorsnap.s.sol \
    --rpc-url https://mainnet.base.org \
    --private-key $PRIVATE_KEY \
    --broadcast --verify

๐ŸŸก Somnia Testnet:

forge script script/Colorsnap.s.sol \
    --rpc-url https://testnet-rpc.somnia.network \
    --private-key $PRIVATE_KEY \
    --broadcast

โšก Electroneum Testnet:

forge script script/DeployElectroneum.s.sol \
    --rpc-url https://testnet-rpc.electroneum.com \
    --private-key $PRIVATE_KEY \
    --broadcast
๐Ÿ” Contract Verification

After deployment, verify your contract:

# Get your contract address from deployment output
CONTRACT_ADDRESS="0x..." # Replace with your address

# Verify the contract is deployed
cast code $CONTRACT_ADDRESS --rpc-url $RPC_URL

# Expected: Non-empty bytecode output means success! โœ…
๐ŸŽจ Step 3: Frontend Setup
# Navigate to frontend directory
cd ../frontend

# Install dependencies
yarn install
# or: npm install

# Create environment file
cp .env.example .env.local
โš™๏ธ Environment Configuration

Add these variables to your .env.local:

# ๐Ÿ“ Your deployed contract address
NEXT_PUBLIC_CONTRACT_ADDRESS=0x...

# ๐ŸŒ RPC URL for your chosen network
NEXT_PUBLIC_RPC_URL=https://...

# โ›“๏ธ Chain ID for your network
NEXT_PUBLIC_CHAIN_ID=8453

# ๐Ÿ”Œ WalletConnect Project ID (get from https://cloud.walletconnect.com)
WALLETCONNECT_PROJECT_ID=your_project_id
๐Ÿ“‹ Quick Copy Templates

Base Mainnet Template:

NEXT_PUBLIC_CONTRACT_ADDRESS=0x62dcaAdAd6D5E6CA4B594CEB636A147537aE7F8f
NEXT_PUBLIC_RPC_URL=https://mainnet.base.org
NEXT_PUBLIC_CHAIN_ID=8453
WALLETCONNECT_PROJECT_ID=your_project_id

Somnia Testnet Template:

NEXT_PUBLIC_CONTRACT_ADDRESS=0xc2dc20E9F389114578F78a7f3C3B071db0b8e8dC
NEXT_PUBLIC_RPC_URL=https://testnet-rpc.somnia.network
NEXT_PUBLIC_CHAIN_ID=50312
WALLETCONNECT_PROJECT_ID=your_project_id
# ๐Ÿš€ Start the development server
yarn run dev
# or: npm run dev
๐Ÿ” Development Server Status Check

Your development server should be running at:

Verify it's working:

# Check if the server is responding
curl -I http://localhost:3000

# Expected: HTTP/200 OK โœ…

Common Issues & Solutions:

  • โŒ Port 3000 in use: Try yarn dev -p 3001
  • โŒ Module not found: Run yarn install again
  • โŒ Environment vars: Check your .env.local file
๐ŸŽ‰ Step 4: Launch & Play!
  1. ๐ŸŒ Open your browser to http://localhost:3000
  2. ๐ŸฆŠ Connect your wallet (MetaMask, WalletConnect, etc.)
  3. ๐Ÿ† Register your champion name on-chain
  4. ๐ŸŽฎ Start your first game and begin matching bottles!

โœ… Success Checklist

  • โœ… Repository cloned and navigated
  • โ›“๏ธ Smart contract deployed successfully
  • ๐Ÿ“ฆ Frontend dependencies installed
  • โš™๏ธ Environment variables configured
  • ๐Ÿš€ Development server running
  • ๐ŸŒ Application accessible in browser
  • ๐ŸฆŠ Wallet connected to correct network
  • ๐Ÿ† Champion name registered
  • ๐ŸŽฎ First game started

๐ŸŽŠ Congratulations! You're ready to play ColorSnap!

๐Ÿ”ง Quick Troubleshooting

Common Issues

๐Ÿšซ "Cannot connect to network"

# Check your RPC URL is working
curl -X POST -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
  $RPC_URL

๐Ÿšซ "Transaction failed"

# Check your balance
cast balance $YOUR_WALLET_ADDRESS --rpc-url $RPC_URL

# Check gas price
cast gas-price --rpc-url $RPC_URL

๐Ÿšซ "Contract not found"

# Verify contract deployment
cast code $CONTRACT_ADDRESS --rpc-url $RPC_URL
# Should return bytecode, not 0x

๐Ÿ“ Project Structure

colorsnap/
โ”œโ”€โ”€ ๐Ÿ“ frontend/                    # Next.js Application
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ components/          # React Components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿงช Bottle.tsx              # Individual bottle component
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐ŸŽฎ ColorSnapGame.tsx       # Main game logic
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ† CongratsMessage.tsx     # Victory celebration
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“– InstructionsModal.tsx   # Game instructions
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ”— WalletConnectButton.tsx # Wallet integration
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“Š Leaderboard components
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ hooks/               # Custom React Hooks
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ”— useContractInteractions.ts  # Contract calls
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ‘‚ useGameCompletedListener.ts # Event listening
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ”’ useTargetRevealLockout.ts   # Peek cooldown
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ app/                 # Next.js App Router
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐ŸŽฎ game/                    # Game page
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ† leaderboard/             # Leaderboard page
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐ŸŽจ globals.css              # Global styles
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ abi/                 # Contract ABI
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ config/              # Configuration files
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ context/             # React Context providers
โ”‚   โ””โ”€โ”€ ๐Ÿ“– README.md                # Frontend documentation
โ”œโ”€โ”€ ๐Ÿ“ smart-contracts/             # Solidity Contracts
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ src/                     # Contract Source Code
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“œ Colorsnap.sol               # Main game contract
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ script/                  # Deployment Scripts
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿš€ Colorsnap.s.sol             # Main deployment
โ”‚   โ”‚   โ”œโ”€โ”€ ๐ŸŒ DeployBase.s.sol            # Base network deployment
โ”‚   โ”‚   โ””โ”€โ”€ โšก DeployElectroneum.s.sol     # Electroneum deployment
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ test/                    # Contract Tests
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿงช ColorSnap.t.sol             # Test suite
โ”‚   โ””โ”€โ”€ ๐Ÿ“– README.md                # Smart contract documentation
โ””โ”€โ”€ ๐Ÿ“– README.md                    # This documentation

๐ŸŽฎ How to Play ColorSnap

๐ŸŽฏ Getting Started

Step 1: Connect Your Wallet ๐ŸฆŠ

  • Use any EVM-compatible wallet (MetaMask, WalletConnect, etc.)
  • Ensure you're connected to the correct network
  • Have some testnet ETH ready for transactions

Step 2: Register Your Champion Name ๐Ÿ†

  • Enter your display name (max 31 characters)
  • Click "๐Ÿ† Register Champion" to save it on-chain
  • This name will appear on the global leaderboard

Step 3: Start Your Challenge ๐Ÿš€

  • Click "๐ŸŽฎ Start New Challenge" to begin
  • Receive 5 colored bottles in random positions
  • A hidden target configuration is generated
๐Ÿงช Game Mechanics

๐ŸŽฏ The Objective

Match your bottle arrangement to the target configuration exactly. Each bottle must be in the correct position with the correct color.

๐ŸŒˆ Available Colors

Color Symbol Description
๐Ÿ”ด Red R The fiery starter
๐Ÿ”ต Blue B The cool challenger
๐ŸŸข Green G The nature warrior
๐ŸŸก Yellow Y The bright contender
๐ŸŸฃ Purple P The royal challenger

๐Ÿ”„ Swapping Mechanics

  1. Select First Bottle: Click the first bottle to move
  2. Select Second Bottle: Click the second bottle to swap with
  3. Automatic Swap: Bottles exchange positions instantly
  4. Move Counter: Each swap counts as one move

๐Ÿ‘๏ธ Peek System

  • ๐Ÿ”’ Locked Until 5 Moves: Must make 5 swaps to unlock
  • โฑ๏ธ 3-Second Peek: View the target for 3 seconds
  • ๐Ÿ• 3-Minute Cooldown: Wait before next peek
  • ๐Ÿ“‹ Strategic Planning: Use peeks wisely!
๐Ÿ† Scoring & Strategy

๐Ÿ“Š Scoring System

  • ๐ŸŽฏ 10 Points per Puzzle: Earned for each completion
  • ๐ŸŽช Move Efficiency: Fewer moves = better strategy
  • ๐ŸŒ Global Ranking: Compete worldwide
  • ๐Ÿ’Ž Permanent Storage: Points stored on-chain forever

๐Ÿง  Winning Strategies

๐Ÿ”ฐ Beginner Tips

  • Start with bottles already in correct positions
  • Work from outside positions inward
  • Count each color to verify you have the right mix
  • Don't peek too early - try solving independently first

๐ŸŽฏ Advanced Techniques

  • Recognize patterns in target arrangements
  • Plan multiple swaps in advance
  • Group similar colors when possible
  • Focus on efficiency and fewer moves

๐Ÿ… Pro Tips

  • Memorize patterns quickly during peeks
  • Work backwards from the target
  • Use the "โœ… Matched" counter strategically
  • Take time to plan - no rush penalties
๐ŸŽ‰ Game Completion

โœ… Successful Submission

  • ๐ŸŽฏ Exact Match Required: All bottles in correct positions
  • ๐Ÿ† 10 Points Awarded: Added to your total score
  • ๐ŸŽŠ Celebration Animation: Victory message displayed
  • ๐Ÿ“ˆ Instant Leaderboard Update: See your new ranking

๏ฟฝ Forfeiting a Game

  • ๏ฟฝ No Points Lost: Existing points remain safe
  • ๐Ÿš€ Immediate Restart: Start new game right away
  • โšก No Penalties: No negative consequences

๏ฟฝ Progress Tracking

  • ๐Ÿ”„ Swap Counter: Number of moves made
  • โœ… Match Counter: Correct bottle positions
  • ๐ŸŽฏ Target Display: Configuration to achieve
  • โšก Transaction Status: Real-time updates

๐Ÿ› ๏ธ Development

๐Ÿ“‹ Development Environment Setup

Prerequisites

  • Node.js 18.0 or higher
  • npm or yarn package manager
  • Foundry for smart contract development
  • Git for version control

Local Development

# Clone the repository
git clone https://github.com/yourusername/colorsnap.git
cd colorsnap

# Install dependencies for both frontend and contracts
cd frontend && yarn install
cd ../smart-contracts && forge install

# Start development servers
cd ../frontend && yarn dev          # Frontend at localhost:3000
forge test                          # Run contract tests
๐Ÿงช Testing

Smart Contract Tests

cd smart-contracts

# Run all tests
forge test

# Run tests with gas reporting
forge test --gas-report

# Run specific test
forge test --match-test testGameFlow

Frontend Testing

cd frontend

# Run unit tests
npm test

# Run e2e tests
npm run test:e2e

# Generate test coverage
npm run test:coverage
โš™๏ธ Configuration

Environment Variables

Create .env.local in the frontend directory:

NEXT_PUBLIC_CONTRACT_ADDRESS=0x...
NEXT_PUBLIC_RPC_URL=https://...
NEXT_PUBLIC_CHAIN_ID=8453
WALLETCONNECT_PROJECT_ID=your_project_id

Network Configuration

Networks are configured in frontend/src/config/chains.ts:

  • Base Mainnet (Primary)
  • Somnia Testnet
  • Electroneum Testnet

๐Ÿš€ Deployment

๐Ÿ“ฆ Smart Contract Deployment

Deploy to Base Mainnet

cd smart-contracts

# Set environment variables
export PRIVATE_KEY="your_private_key"
export RPC_URL="https://mainnet.base.org"

# Deploy contract
forge script script/Colorsnap.s.sol \
    --rpc-url $RPC_URL \
    --private-key $PRIVATE_KEY \
    --broadcast \
    --verify

Deploy to Testnets

# Somnia Testnet
forge script script/Colorsnap.s.sol \
    --rpc-url https://testnet-rpc.somnia.network \
    --private-key $PRIVATE_KEY \
    --broadcast

# Electroneum Testnet  
forge script script/DeployElectroneum.s.sol \
    --rpc-url https://testnet-rpc.electroneum.com \
    --private-key $PRIVATE_KEY \
    --broadcast
๐ŸŒ Frontend Deployment

Deploy to Vercel

# Install Vercel CLI
npm i -g vercel

# Deploy
cd frontend
vercel

# Set environment variables in Vercel dashboard
# NEXT_PUBLIC_CONTRACT_ADDRESS
# NEXT_PUBLIC_RPC_URL
# NEXT_PUBLIC_CHAIN_ID

Deploy to Netlify

# Build the application
cd frontend
npm run build

# Deploy to Netlify
npx netlify deploy --prod --dir=out

Other Hosting Options

  • GitHub Pages: Static export with next export
  • AWS S3: Static hosting with CloudFront
  • Firebase Hosting: Google's hosting platform
  • IPFS: Decentralized hosting

๐Ÿค Contributing

We welcome contributions from the community! Here's how to get involved:

๐Ÿ“ Contribution Guidelines

Getting Started

  1. Fork the repository
  2. Clone your fork locally
  3. Create a feature branch: git checkout -b feature/amazing-feature
  4. Make your changes
  5. Test thoroughly
  6. Commit with clear messages: git commit -m 'Add amazing feature'
  7. Push to your branch: git push origin feature/amazing-feature
  8. Submit a pull request

Code Standards

  • TypeScript for type safety
  • ESLint for code linting
  • Prettier for code formatting
  • Conventional Commits for commit messages
  • Comprehensive tests for new features

Areas for Contribution

  • ๐ŸŽฎ Game Features: New game modes, power-ups, achievements
  • ๐ŸŽจ UI/UX: Design improvements, animations, accessibility
  • โ›“๏ธ Blockchain: Multi-chain support, gas optimization
  • ๐Ÿ“ฑ Mobile: React Native app, PWA enhancements
  • ๐Ÿ“š Documentation: Tutorials, API docs, translations
  • ๐Ÿงช Testing: Unit tests, integration tests, e2e tests

๐Ÿ“„ License

MIT License

Copyright (c) 2024 ColorSnap Game

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software.


Connect With Us

GitHub
Source Code
Contribute & Star โญ
Twitter
Updates
Latest news & tips
Discord
Community
Chat & support
GitBook
Documentation
Detailed guides
Medium
Blog
Dev insights
YouTube
Tutorials
Video guides
๐Ÿ“Š Project Statistics

GitHub repo size GitHub code size in bytes GitHub commit activity GitHub last commit

Development Activity:

  • ๐ŸŽฏ Latest Release: v1.0.0
  • ๐Ÿ“ˆ Commits This Month: 24
  • ๐Ÿ› Open Issues: 3
  • โœ… Closed Issues: 17
  • ๐Ÿ‘ฅ Contributors: 4

Made with โค๏ธ by the ColorSnap team
โญ Star us on GitHub if you like this project!

Visitor Count GitHub Release Date GitHub

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors