diff --git a/.cursor/documentation-reference.md b/.cursor/documentation-reference.md new file mode 100644 index 00000000..9a119ed9 --- /dev/null +++ b/.cursor/documentation-reference.md @@ -0,0 +1,151 @@ +# Documentation Reference - Base Blockchain Development + +This document contains the most up-to-date documentation links for all technologies used in this project. Last updated: 2024 + +## 📚 Core Base Documentation + +### Base Chain & Ecosystem +- **Base Documentation Home**: https://docs.base.org/ +- **Base Full Documentation (LLM Format)**: https://docs.base.org/llms-full.txt +- **Base Chain Info**: https://docs.base.org/ + +### Base Account +- **Base Account Overview**: https://docs.base.org/base-account +- **Authentication Guide**: https://docs.base.org/base-account/guides/authenticate-users +- **Sub Accounts Guide**: https://docs.base.org/base-account/improve-ux/sub-accounts +- **Base Account SDK Reference**: https://docs.base.org/base-account/reference/account-sdk +- **Spend Permissions**: https://docs.base.org/base-account/improve-ux/spend-permissions + +## 🔧 OnchainKit Documentation + +### Getting Started +- **OnchainKit Overview**: https://docs.base.org/builderkits/onchainkit +- **OnchainKit LLM Format (for AI assistants)**: https://docs.base.org/builderkits/onchainkit/llms.txt +- **Installation - Next.js**: https://docs.base.org/builderkits/onchainkit/installation/nextjs +- **Installation - Vite**: https://docs.base.org/builderkits/onchainkit/installation/vite +- **Installation - Remix**: https://docs.base.org/builderkits/onchainkit/installation/remix +- **Installation - Astro**: https://docs.base.org/builderkits/onchainkit/installation/astro + +### OnchainKit Components +- **Identity Component**: https://docs.base.org/builderkits/onchainkit/identity/identity + - Basenames: https://docs.base.org/builderkits/onchainkit/identity/identity + - Avatars: https://docs.base.org/builderkits/onchainkit/identity/avatar + - Badges: https://docs.base.org/builderkits/onchainkit/identity/badge + - Addresses: https://docs.base.org/builderkits/onchainkit/identity/address + +- **Wallet Component**: https://docs.base.org/builderkits/onchainkit/wallet/wallet + - Connect Wallet: https://docs.base.org/builderkits/onchainkit/wallet/wallet + +- **Transaction Component**: https://docs.base.org/builderkits/onchainkit/transaction/transaction + +- **Checkout Component**: https://docs.base.org/builderkits/onchainkit/checkout/checkout + +- **Fund Component**: https://docs.base.org/builderkits/onchainkit/fund/fund-button + +- **Token Components**: https://docs.base.org/builderkits/onchainkit/token/token-chip + +- **Swap Component**: https://docs.base.org/builderkits/onchainkit/swap/swap + +- **NFT Mint Card**: https://docs.base.org/builderkits/onchainkit/mint/nft-mint-card + +### OnchainKit Guides +- **Tailwind Integration**: https://docs.base.org/builderkits/onchainkit/guides/tailwind +- **Theming Guide**: https://docs.base.org/builderkits/onchainkit/guides/themes +- **Configuration - Supplemental Providers**: https://docs.base.org/builderkits/onchainkit/config/supplemental-providers + +## 💰 Coinbase Developer Platform (CDP) + +### API & Portal +- **CDP Portal - Client API Keys**: https://portal.cdp.coinbase.com/projects/api-keys/client-key +- **CDP Portal Home**: https://portal.cdp.coinbase.com/ + +### CDP Services +- **Paymaster/Gas Sponsorship**: https://docs.base.org/docs/tools/paymaster +- **Smart Accounts**: https://docs.base.org/docs/tools/smart-accounts +- **Server Wallets**: https://docs.base.org/docs/tools/server-wallets + +## 🔗 Third-Party Libraries + +### Viem +- **Viem Documentation**: https://viem.sh/ +- **Viem LLM Format (for AI assistants)**: https://viem.sh/llms-full.txt + +### Wagmi +- **Wagmi Documentation**: https://wagmi.sh/ + +### Privy +- **Privy Documentation**: https://docs.privy.io/ +- **Privy React SDK**: https://docs.privy.io/reference/react-auth + +### Next.js +- **Next.js Documentation**: https://nextjs.org/docs +- **Next.js Deployment**: https://nextjs.org/docs/app/building-your-application/deploying + +## 📱 Mini Apps (Base App) + +### MiniKit Documentation +- **MiniKit Overview**: https://docs.base.org/docs/builderkits/minikit +- **MiniKit SDK**: https://docs.base.org/docs/builderkits/minikit/sdk +- **MiniKit Templates**: Available in `mini-apps/templates/` directory + +### Mini App Development +- **Base App Integration**: https://docs.base.org/docs/builderkits/minikit +- **Mini App Validation**: See `mini-apps/mini-app-validation/README.md` + +## 🎮 Onchain Gaming + +### Game Development Resources +- **Paymaster for Games**: See `paymaster/hangman-onchain/` and `paymaster/onchain-game-lingos/` for examples +- **CDP Paymaster**: https://docs.base.org/docs/tools/paymaster + +## 📦 Templates & Examples + +### OnchainKit Templates +- **Onchain Commerce**: https://onchain-commerce-template.vercel.app/ +- **NFT Minting**: https://ock-mint.vercel.app/ +- **Funding Flow**: https://github.com/fakepixels/fund-component +- **Social Profile**: https://github.com/fakepixels/ock-identity + +### Quick Start Command +```bash +npm create onchain@latest +``` + +## 🚀 Deployment + +### Vercel +- **Vercel Platform**: https://vercel.com/new +- **Next.js Deployment**: https://nextjs.org/docs/app/building-your-application/deploying + +## 📝 Additional Resources + +### Base Ecosystem +- **Base Website**: https://base.org/ +- **Base Blog**: https://base.org/blog +- **Base Discord**: Community support available + +### Development Tools +- **Base Explorer**: https://basescan.org/ +- **Base Sepolia Testnet Explorer**: https://sepolia.basescan.org/ + +## 🔄 Keeping Documentation Updated + +To ensure you have the latest documentation: +1. Check the official documentation sites listed above regularly +2. Review release notes and changelogs for breaking changes +3. Follow Base ecosystem announcements for updates +4. Check package.json versions against latest releases + +## 📋 Quick Reference URLs + +### Most Frequently Used +- Base Docs: https://docs.base.org/ +- OnchainKit LLM Docs: https://docs.base.org/builderkits/onchainkit/llms.txt +- Base LLM Full Docs: https://docs.base.org/llms-full.txt +- Viem LLM Docs: https://viem.sh/llms-full.txt +- CDP Portal: https://portal.cdp.coinbase.com/ + +--- + +**Note**: This document should be updated periodically as documentation evolves. Check official sources for the most current information. + diff --git a/.cursor/rules/projectrules.mdc b/.cursor/rules/projectrules.mdc new file mode 100644 index 00000000..d1f863bc --- /dev/null +++ b/.cursor/rules/projectrules.mdc @@ -0,0 +1,53 @@ +# Instructions + +You are a multi-agent system coordinator, playing two roles in this environment: Planner and Executor. You will decide the next steps based on the current state in the `.cursor/scratchpad.md` file. Your goal is to complete the user's final requirements. + +When the user asks for something to be done, you will take on one of two roles: the Planner or Executor. Any time a new request is made, the human user will ask to invoke one of the two modes. If the human user doesn't specifiy, please ask the human user to clarify which mode to proceed in. + +The specific responsibilities and actions for each role are as follows: + +## Role Descriptions + +1. Planner + - Responsibilities: Perform high-level analysis, break down tasks, define success criteria, evaluate current progress. The human user will ask for a feature or change, and your task is to think deeply and document a plan so the human user can review before giving permission to proceed with implementation. When creating task breakdowns, make the tasks as small as possible with clear success criteria. Do not overengineer anything, always focus on the simplest, most efficient approaches. + - Actions: Revise the `.cursor/scratchpad.md` file to update the plan accordingly. +2. Executor + - Responsibilities: Execute specific tasks outlined in `.cursor/scratchpad.md`, such as writing code, running tests, handling implementation details, etc.. The key is you need to report progress or raise questions to the human at the right time, e.g. after completion some milestone or after you've hit a blocker. Simply communicate with the human user to get help when you need it. + - Actions: When you complete a subtask or need assistance/more information, also make incremental writes or modifications to `.cursor/scratchpad.md `file; update the "Current Status / Progress Tracking" and "Executor's Feedback or Assistance Requests" sections; if you encounter an error or bug and find a solution, document the solution in "Lessons" to avoid running into the error or bug again in the future. + +## Document Conventions + +- The `.cursor/scratchpad.md` file is divided into several sections as per the above structure. Please do not arbitrarily change the titles to avoid affecting subsequent reading. +- Sections like "Background and Motivation" and "Key Challenges and Analysis" are generally established by the Planner initially and gradually appended during task progress. +- "High-level Task Breakdown" is a step-by-step implementation plan for the request. When in Executor mode, only complete one step at a time and do not proceed until the human user verifies it was completed. Each task should include success criteria that you yourself can verify before moving on to the next task. +- "Project Status Board" and "Executor's Feedback or Assistance Requests" are mainly filled by the Executor, with the Planner reviewing and supplementing as needed. +- "Project Status Board" serves as a project management area to facilitate project management for both the planner and executor. It follows simple markdown todo format. + +## Workflow Guidelines + +- After you receive an initial prompt for a new task, update the "Background and Motivation" section, and then invoke the Planner to do the planning. +- When thinking as a Planner, always record results in sections like "Key Challenges and Analysis" or "High-level Task Breakdown". Also update the "Background and Motivation" section. +- When you as an Executor receive new instructions, use the existing cursor tools and workflow to execute those tasks. After completion, write back to the "Project Status Board" and "Executor's Feedback or Assistance Requests" sections in the `.cursor/scratchpad.md` file. +- Adopt Test Driven Development (TDD) as much as possible. Write tests that well specify the behavior of the functionality before writing the actual code. This will help you to understand the requirements better and also help you to write better code. +- Test each functionality you implement. If you find any bugs, fix them before moving to the next task. +- When in Executor mode, only complete one task from the "Project Status Board" at a time. Inform the user when you've completed a task and what the milestone is based on the success criteria and successful test results and ask the user to test manually before marking a task complete. +- Continue the cycle unless the Planner explicitly indicates the entire project is complete or stopped. Communication between Planner and Executor is conducted through writing to or modifying the `.cursor/scratchpad.md` file. + "Lesson." If it doesn't, inform the human user and prompt them for help to search the web and find the appropriate documentation or function. + +Please note: +- Note the task completion should only be announced by the Planner, not the Executor. If the Executor thinks the task is done, it should ask the human user planner for confirmation. Then the Planner needs to do some cross-checking. +- Avoid rewriting the entire document unless necessary; +- Avoid deleting records left by other roles; you can append new paragraphs or mark old paragraphs as outdated; +- When new external information is needed, you can inform the human user planner about what you need, but document the purpose and results of such requests; +- Before executing any large-scale changes or critical functionality, the Executor should first notify the Planner in "Executor's Feedback or Assistance Requests" to ensure everyone understands the consequences. +- During your interaction with the human user, if you find anything reusable in this project (e.g. version of a library, model name), especially about a fix to a mistake you made or a correction you received, you should take note in the `Lessons` section in the `.cursor/scratchpad.md` file so you will not make the same mistake again. +- When interacting with the human user, don't give answers or responses to anything you're not 100% confident you fully understand. The human user is non-technical and won't be able to determine if you're taking the wrong approach. If you're not sure about something, just say it. + +### User Specified Lessons + +- Include info useful for debugging in the program output. +- Read the file before you try to edit it. +- If there are vulnerabilities that appear in the terminal, run npm audit before proceeding +- Always ask before using the -force git command--- +alwaysApply: true +--- diff --git a/.cursor/scratchpad.md b/.cursor/scratchpad.md new file mode 100644 index 00000000..56f2e831 --- /dev/null +++ b/.cursor/scratchpad.md @@ -0,0 +1,332 @@ +# Hangman Onchain Game - Project Scratchpad + +## Background and Motivation + +This project is building an onchain Hangman word-guessing game where players can: +- Play the classic Hangman game across different word categories +- Earn onchain rewards when they successfully guess words +- Compete on leaderboards +- Experience gasless transactions through Coinbase CDP (Coinbase Developer Platform) integration + +The game is built using: +- **Next.js 14+ (App Router)** with TypeScript +- **TailwindCSS** for styling +- **Wagmi** for wallet management +- **Viem** for blockchain interactions +- **OnchainKit** for onchain-ready UI components +- **Coinbase CDP** for gasless transactions and account abstraction + +The project was bootstrapped using `npm create onchain` which provides a developer-ready scaffold with all the necessary dependencies. + +## Key Challenges and Analysis + +### Technical Challenges Identified: + +1. **Game State Management**: Currently, game state is managed locally within components. A centralized `GameStateProvider` would improve state management across the application. + +2. **Onchain Integration**: The game needs to interact with smart contracts for: + - Starting games (`startGame` function) + - Recording wins (`recordReward` function via CDP account) + - Claiming rewards (if applicable) + +3. **Leaderboard System**: Need to implement Redis (Upstash) integration for persistent score tracking and leaderboard display. + +4. **User Experience Flow**: Need dedicated `/fail` and `/win` pages for better UX when games end, rather than handling everything in the game screen. + +5. **Score Calculation**: Currently using a hardcoded score (100). Need a proper scoring system based on: + - Number of wrong guesses + - Time taken + - Hints used + +### Current Implementation Status: + +✅ **Completed:** +- Welcome screen (`/`) with wallet connection and game introduction +- Category selection page (`/category-select`) that loads categories from `wordCategories.json` +- Game screen (`/game/[category]`) with full game logic: + - Word display with masked letters + - Letter guessing system (A-Z keyboard) + - Wrong guess tracking (max 3 attempts) + - Win/loss detection + - Hints system (progressive reveal) + - Onchain win recording via `/api/win` endpoint +- `PlayButton` component for starting games with onchain transaction +- `/api/win` endpoint that records wins onchain using Coinbase CDP +- CDP integration for gasless transactions + +❌ **Missing/Incomplete:** +- `/fail` page for game over screen +- `/win` page for dedicated win screen with claim options +- `GameStateProvider` for centralized state management +- Leaderboard system (Redis/Upstash integration) +- `/api/leaderboard` endpoint for score tracking +- Score calculation system +- `ScoreBoard` component for displaying leaderboards +- Proper score tracking (currently hardcoded to 100) +- Word progression system (next word after win) + +## High-level Task Breakdown + +### Phase 1: Complete Core Game Flow Pages +**Goal**: Add missing result pages to complete the basic game flow + +#### Task 1.1: Create `/fail` Page +- **Description**: Create a dedicated page for when players lose the game +- **Success Criteria**: + - Page displays at `/fail` route + - Shows "You lost! Try again?" message + - Has "Play Again" button that navigates to `/category-select` + - Has "Back to Home" button that navigates to `/` + - Matches the design style of other pages +- **Estimated Complexity**: Low +- **Dependencies**: None + +#### Task 1.2: Create `/win` Page +- **Description**: Create a dedicated page for when players win, with claim reward functionality +- **Success Criteria**: + - Page displays at `/win` route + - Shows win message and score + - Displays transaction hash if win was recorded onchain + - Has "Next Word" button to continue playing + - Has "Back to Home" button + - Optionally shows claim reward button (if rewards are claimable) +- **Estimated Complexity**: Medium +- **Dependencies**: Task 1.1 (for consistency) + +#### Task 1.3: Update Game Screen Navigation +- **Description**: Update the game screen to navigate to `/fail` or `/win` pages instead of showing results inline +- **Success Criteria**: + - On loss, redirects to `/fail` page + - On win, redirects to `/win` page with relevant game data + - Passes necessary state (score, txHash, etc.) via URL params or state +- **Estimated Complexity**: Low +- **Dependencies**: Tasks 1.1 and 1.2 + +### Phase 2: Game State Management +**Goal**: Implement centralized state management for better code organization + +#### Task 2.1: Create `GameStateProvider` +- **Description**: Create a React context provider for managing game state globally +- **Success Criteria**: + - Context provides: selected category, current word, attempt count, score, game history + - Provider wraps the application in `layout.tsx` or `providers.tsx` + - State persists across navigation (or can be reset as needed) + - TypeScript types are properly defined +- **Estimated Complexity**: Medium +- **Dependencies**: None + +#### Task 2.2: Refactor Components to Use GameStateProvider +- **Description**: Update existing components to use the centralized state +- **Success Criteria**: + - Game screen uses context instead of local state where appropriate + - Category selection updates context + - State is properly shared between components + - No breaking changes to existing functionality +- **Estimated Complexity**: Medium +- **Dependencies**: Task 2.1 + +### Phase 3: Score System and Leaderboard +**Goal**: Implement proper scoring and leaderboard functionality + +#### Task 3.1: Implement Score Calculation System +- **Description**: Create a scoring algorithm based on game performance +- **Success Criteria**: + - Score calculation considers: wrong guesses (fewer = higher score), hints used (fewer = higher score), time taken (optional) + - Score is calculated and stored when game is won + - Score is displayed in game UI and win screen +- **Estimated Complexity**: Medium +- **Dependencies**: Task 2.1 + +#### Task 3.2: Set Up Redis/Upstash Integration +- **Description**: Configure Upstash Redis for leaderboard storage +- **Success Criteria**: + - Redis client is configured in `lib/redis.ts` + - Environment variables are documented + - Connection is tested and working +- **Estimated Complexity**: Low +- **Dependencies**: None + +#### Task 3.3: Create `/api/leaderboard` Endpoint +- **Description**: Create API route for leaderboard operations +- **Success Criteria**: + - POST endpoint accepts `{ address, score }` and stores in Redis + - GET endpoint returns top N players sorted by score + - Proper error handling and validation + - Returns data in format: `{ leaderboard: [{ address, score, rank }] }` +- **Estimated Complexity**: Medium +- **Dependencies**: Task 3.2 + +#### Task 3.4: Create `ScoreBoard` Component +- **Description**: Create a component to display the leaderboard +- **Success Criteria**: + - Component fetches leaderboard data from API + - Displays top players with ranks, addresses, and scores + - Updates when new scores are submitted + - Shows current player's rank if applicable + - Responsive design matching app style +- **Estimated Complexity**: Medium +- **Dependencies**: Task 3.3 + +#### Task 3.5: Integrate Leaderboard into Home Page +- **Description**: Add leaderboard display to the welcome screen +- **Success Criteria**: + - Leaderboard is displayed on home page + - Updates automatically or has refresh button + - Doesn't interfere with existing home page layout +- **Estimated Complexity**: Low +- **Dependencies**: Task 3.4 + +#### Task 3.6: Update Win API to Submit Scores +- **Description**: Modify `/api/win` to also submit score to leaderboard +- **Success Criteria**: + - After recording win onchain, score is submitted to leaderboard + - Error handling if leaderboard submission fails (shouldn't block onchain recording) + - Score is properly calculated before submission +- **Estimated Complexity**: Low +- **Dependencies**: Task 3.1, Task 3.3 + +### Phase 4: UI/UX Enhancements +**Goal**: Polish the user experience and add missing features + +#### Task 4.1: Improve Game Screen Visual Feedback +- **Description**: Enhance visual feedback for game state +- **Success Criteria**: + - Better hangman visualization (SVG or ASCII art) + - Animations for correct/wrong guesses + - Better visual distinction between guessed and unguessed letters + - Progress indicators +- **Estimated Complexity**: Medium +- **Dependencies**: None + +#### Task 4.2: Add Word Progression System +- **Description**: Allow players to continue to next word in category after winning +- **Success Criteria**: + - After winning, player can choose "Next Word" to continue in same category + - Tracks which words have been played to avoid repeats (or allows repeats) + - Maintains score across multiple words +- **Estimated Complexity**: Medium +- **Dependencies**: Task 2.1 + +#### Task 4.3: Add Loading States and Error Handling +- **Description**: Improve loading states and error messages throughout the app +- **Success Criteria**: + - All async operations show loading states + - Error messages are user-friendly + - Network errors are handled gracefully + - Transaction errors provide helpful feedback +- **Estimated Complexity**: Low +- **Dependencies**: None + +### Phase 5: Testing and Polish +**Goal**: Ensure everything works correctly and is production-ready + +#### Task 5.1: End-to-End Testing +- **Description**: Test the complete game flow from start to finish +- **Success Criteria**: + - Complete game flow works: Home → Category → Game → Win/Fail → Navigation + - Onchain transactions complete successfully + - Leaderboard updates correctly + - No console errors or warnings +- **Estimated Complexity**: Low +- **Dependencies**: All previous phases + +#### Task 5.2: Code Review and Refactoring +- **Description**: Review code for best practices and refactor as needed +- **Success Criteria**: + - Code follows TypeScript best practices + - Components are properly organized + - No duplicate code + - Proper error boundaries +- **Estimated Complexity**: Medium +- **Dependencies**: All previous phases + +## Project Status Board + +### Current Sprint / Active Tasks + +- [ ] **Task 1.1**: Create `/fail` Page +- [ ] **Task 1.2**: Create `/win` Page +- [ ] **Task 1.3**: Update Game Screen Navigation + +### Backlog / Pending Tasks + +- [ ] **Task 2.1**: Create `GameStateProvider` +- [ ] **Task 2.2**: Refactor Components to Use GameStateProvider +- [ ] **Task 3.1**: Implement Score Calculation System +- [ ] **Task 3.2**: Set Up Redis/Upstash Integration +- [ ] **Task 3.3**: Create `/api/leaderboard` Endpoint +- [ ] **Task 3.4**: Create `ScoreBoard` Component +- [ ] **Task 3.5**: Integrate Leaderboard into Home Page +- [ ] **Task 3.6**: Update Win API to Submit Scores +- [ ] **Task 4.1**: Improve Game Screen Visual Feedback +- [ ] **Task 4.2**: Add Word Progression System +- [ ] **Task 4.3**: Add Loading States and Error Handling +- [ ] **Task 5.1**: End-to-End Testing +- [ ] **Task 5.2**: Code Review and Refactoring + +### Completed Tasks + +- [x] Welcome screen with wallet connection +- [x] Category selection page +- [x] Game screen with full game logic +- [x] Onchain win recording via `/api/win` endpoint +- [x] `PlayButton` component for starting games +- [x] CDP integration for gasless transactions + +## Current Status / Progress Tracking + +### Last Updated: [Current Date] + +**Current Phase**: Phase 1 - Complete Core Game Flow Pages + +**Recent Progress**: +- Core game functionality is implemented and working +- Players can select categories, play games, and have wins recorded onchain +- Basic game flow is functional but missing dedicated result pages + +**Current Blocker**: None + +**Next Steps**: +1. Create `/fail` page for game over scenarios +2. Create `/win` page for win scenarios with better UX +3. Update game screen to navigate to these pages instead of showing results inline + +## Executor's Feedback or Assistance Requests + +*This section will be updated by the Executor as tasks are completed or blockers are encountered.* + +**Current Requests**: None + +**Completed Milestones**: +- Basic game flow is working +- Onchain integration is functional + +## Lessons + +### User Specified Lessons +- Include info useful for debugging in the program output +- Read the file before you try to edit it +- If there are vulnerabilities that appear in the terminal, run npm audit before proceeding +- Always ask before using the -force git command + +### Project-Specific Lessons +- The game uses Coinbase CDP for gasless transactions via the `/api/win` endpoint +- Game contract address: `0x9a68a6af680e33c59b7e1c34ecc8bbedf6b5b75b` (hardcoded in win route) +- Word categories are loaded from `/public/wordCategories.json` +- The game currently uses a hardcoded score of 100 - this needs to be replaced with a proper scoring system +- CDP environment variables required: `CDP_API_KEY_ID`, `CDP_API_KEY_SECRET`, `CDP_WALLET_SECRET`, `CDP_SIGNER_ADDRESS`, `GAME_CONTRACT_ADDRESS_SEPOLIA` + +## Notes and Observations + +- The game screen currently handles win/loss states inline, but the plan calls for dedicated `/fail` and `/win` pages for better UX +- Score calculation is not yet implemented - currently hardcoded to 100 +- Leaderboard system is planned but not yet implemented +- The `PlayButton` component successfully integrates with smart contracts using wagmi's `useSendCalls` hook +- CDP integration is working for recording wins onchain without requiring user gas + +--- + +**Document Status**: Active Planning Phase +**Last Reviewed By**: Planner +**Next Review**: After Phase 1 completion + diff --git a/baselaunch/index.html b/baselaunch/index.html new file mode 100644 index 00000000..be582d28 --- /dev/null +++ b/baselaunch/index.html @@ -0,0 +1,1867 @@ + + +
+ + + ++ The premier platform for discovering trending apps, launching your project, and growing your community on Base. +
+ + +