A fun Next.js web game that integrates with the thirdweb API to create a clicking game where players earn tokens for hitting targets.
- User Authentication: Enter a username to automatically create a wallet
- Persistent Sessions: Your account is remembered - no need to re-enter username on reload
- Clicking Game: Click on randomly spawning targets within a 10-second timer
- Token Rewards: Earn 0.01 tokens for each target hit
- Real-time Transactions: See transaction status updates in real-time
- Balance Tracking: View your current token balance with auto-refresh
- Account Switching: Easily switch between different user accounts
- Responsive Design: Built with Tailwind CSS and shadcn components
- Frontend: Next.js 14 with App Router, TypeScript, Tailwind CSS
- UI Components: shadcn/ui components
- Blockchain Integration: thirdweb API
- Styling: Tailwind CSS with custom game animations
-
Install Dependencies
pnpm install
-
Environment Configuration
- Copy
env.template
to.env.local
:
cp env.template .env.local
- Fill in your environment variables in
.env.local
:
THIRDWEB_SECRET_KEY=your_thirdweb_secret_key_here TREASURY_WALLET_ADDRESS=0x... TOKEN_CONTRACT_ADDRESS=0x... CHAIN_ID=8453 THIRDWEB_API_BASE_URL=https://api.thirdweb-dev.com
- Copy
-
Required Setup
- Get your thirdweb secret key from the thirdweb dashboard
- Deploy or have access to an ERC-20 token contract
- Set up a treasury server wallet with sufficient token balance
-
Run the Development Server
pnpm dev
-
Open the Game
- Navigate to
http://localhost:3000
- Enter a username to create a wallet and start playing
- Navigate to
Variable | Description |
---|---|
THIRDWEB_SECRET_KEY |
Your thirdweb secret key for backend authentication |
TREASURY_WALLET_ADDRESS |
Wallet address that holds and distributes tokens |
TOKEN_CONTRACT_ADDRESS |
Address of the ERC-20 token contract |
CHAIN_ID |
Blockchain network ID (e.g., 8453 for Base) |
THIRDWEB_API_BASE_URL |
thirdweb API base URL |
- Login: Enter a username to create your wallet (remembered for future visits)
- Start Game: Click "Start Game" to begin a 10-second round
- Hit Targets: Click on red targets that appear randomly
- Earn Tokens: Each target hit earns 0.01 tokens
- Track Progress: View your balance and transaction history
- Play Again: Start new rounds to earn more tokens
- Switch Account: Use "Switch Account" to log in with a different username
POST /api/user
- Create/login user with walletGET /api/balance
- Get user's token balancePOST /api/reward
- Send tokens to user (called on target hit)GET /api/transaction/[id]
- Get transaction statusGET /api/transactions
- List recent transactions
All thirdweb API logic is contained in src/lib/thirdweb.ts
. This file handles wallet creation, token transfers, balance queries, and transaction management through the thirdweb SDK.
LoginForm
- User authenticationGameHeader
- User info and balance displayGameArena
- Main game area with target spawningTransactionList
- Real-time transaction history
- React hooks for local state management
- Real-time transaction polling for status updates
- Automatic balance refresh every 5 seconds (with throttling)
Edit the constants in src/components/game/game-arena.tsx
:
const GAME_DURATION = 10000; // 10 seconds
const TARGET_SPAWN_INTERVAL = 2000; // 2 seconds
const TARGET_LIFETIME = 3000; // 3 seconds
Edit the reward amount in src/app/api/reward/route.ts
:
const REWARD_AMOUNT = "10000000000000000"; // 0.01 tokens (18 decimals)
- Wallet Creation Fails: Check your thirdweb secret key
- No Tokens Received: Ensure treasury wallet has sufficient balance
- Transaction Failures: Verify token contract address and chain ID
- Balance Not Updating: Check API connectivity and refresh manually
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
Apache 2.0. This project is for educational purposes.