• Homepage •
Supported protocols •
Chainstack blog •
Chainstack docs •
Blockchain API reference •
• Start for free •
This project is the practical part of a tutorial that outlines how to build a game of Battleship on the Ethereum blockchain. It discusses the challenges of storing private data on a public blockchain and proposes a solution that uses public-private signatures to ensure that the players' ship coordinates remain private while still allowing the game to be played on the blockchain.
Clone the repository:
git clone https://github.com/chainstacklabs/zk-battleship-game-hardhat.gitInstall dependencies:
npm installRun tests:
npx hardhat testAdd environment variables to .env.sample and rename to .env:
Deploy a node with Chainstack:
In this specific version we specify the account playing by taking the private key from the environment variable. Develop this further by adding a user interface.
SEPOLIA_ENDPOINT="YOUR_CHAINSTACK_ENDPOINT"
GOERLI_ENDPOINT="YOUR_CHAINSTACK_ENDPOINT"
MAINNET_URL="YOUR_CHAINSTACK_ENDPOINT"
PRIVATE_KEY="PRIVATE_KEY_1"
PRIVATE_KEY_2="PRIVATE_KEY_2"
ETHERSCAN="ETHERSCAN_API_KEY"Use the Chainstack faucet to get test funds:
Deploy the smart contract:
npx hardhat run scripts/deploy.ts --network sepoliaor
npx hardhat run scripts/deploy.ts --network goerliNow the contract will be deployed and verified on Etherscan.
Compiled 3 Solidity files successfully
Deploying contract...
BattleShipGame was deployed at: 0x27F1a73dB2aCD037B9AeAA993F1A2D6c5606456B
Waiting for 3 blocks...
3 blocks have passed!
Verifying contract...
Contract verified!
The contract 0x27F1a73dB2aCD037B9AeAA993F1A2D6c5606456B has already been verified