A fully functional Battleship game implementation using Merkle proofs for verification without zero-knowledge proofs.
Click on each file name below to download:
- Smart Contract:
ImprovedOnChainBattleship.sol - Package Config:
package.json - Hardhat Config:
hardhat.config.js - Deployment Script:
deploy.js - Environment Template:
.env.example
mkdir onchain-battleship
cd onchain-battleshipnpm init -ynpm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
npm install @openzeppelin/contractsmkdir contracts
mkdir scripts
mkdir test- Move
ImprovedOnChainBattleship.soltocontracts/ - Move
deploy.jstoscripts/ - Keep
hardhat.config.jsandpackage.jsonin root directory - Copy
.env.exampleto.envand fill in your values
cp .env.example .envPRIVATE_KEY=your_private_key_here
SEPOLIA_RPC_URL=https://rpc.sepolia.org
ETHERSCAN_API_KEY=your_etherscan_api_key_herenpx hardhat compilenpx hardhat run scripts/deploy.js --network sepolianpx hardhat verify CONTRACT_ADDRESS --network sepoliaonchain-battleship/
โโโ contracts/
โ โโโ ImprovedOnChainBattleship.sol
โโโ scripts/
โ โโโ deploy.js
โโโ test/
โโโ hardhat.config.js
โโโ package.json
โโโ .env.example
โโโ README.md
The frontend is completely standalone and works without any blockchain connection:
- Ship Placement: Drag and drop 5 ships onto your 10x10 grid
- Battle Phase: Click enemy grid squares to attack
- Visual Effects: See explosions for hits, splashes for misses
- Victory: Game ends when all ships are destroyed
- ReentrancyGuard: Prevents reentrancy attacks
- Pausable: Emergency stop functionality
- Ownable: Owner controls for emergency situations
- Input Validation: Coordinate and state validation
- Timeout System: Prevents griefing attacks
- Merkle Proof Verification: All moves verified cryptographically
- Anti-Cheat System: Economic penalties for invalid proofs
- Timeout Mechanisms: 24-hour move timeout, 7-day reveal timeout
- Slashing Logic: Cheaters forfeit their stakes
- Stake: 0.1 ETH per game (perfect for testnet)
- Winner Takes All: Winner receives both stakes (0.2 ETH total)
- Slashing: Cheaters lose their stake to honest players
- Timeouts: Non-responsive players forfeit their stakes
npx hardhat testnpx hardhat node- Sepolia Testnet: Recommended for testing
- Goerli Testnet: Alternative testnet
- Mainnet: Production deployment
- Standard Battleship: 5 ships (Carrier:5, Battleship:4, Cruiser:3, Submarine:3, Destroyer:2)
- Turn-Based: Players alternate making guesses
- Merkle Proofs: All hits/misses verified cryptographically
- Win Condition: First to sink all opponent ships wins
- Anti-Cheat: Invalid proofs result in automatic loss
- "Invalid private key": Make sure your private key is 64 characters (without 0x prefix)
- "Insufficient funds": Ensure your wallet has testnet ETH
- "Contract not found": Check if contract address is correct
- "Network error": Verify RPC URL is working
- Sepolia: https://sepoliafaucet.com/
- Goerli: https://goerlifaucet.com/
- Test Locally: Deploy to local hardhat network
- Testnet Deployment: Deploy to Sepolia testnet
- Frontend Integration: Connect frontend to deployed contract
- Security Audit: Professional security review
- Mainnet Launch: Production deployment
For questions or issues:
- Check the troubleshooting section
- Review Hardhat documentation
- Test on local network first
- Verify all environment variables are set correctly
Status: Ready for deployment and testing! ๐ขโ
