Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/chainstacklabs/zk-battleship-game-hardhat

This repository provides a hands-on tutorial on how to develop a battleship game using zero-knowledge principles
https://github.com/chainstacklabs/zk-battleship-game-hardhat

chainstack game smat-contracts solidity zero-knowledge

Last synced: 5 days ago
JSON representation

This repository provides a hands-on tutorial on how to develop a battleship game using zero-knowledge principles

Awesome Lists containing this project

README

        

Labs


Chainstack is the leading suite of services connecting developers with Web3 infrastructure


 
 
 
 
 


Homepage
Supported protocols
Chainstack blog
Chainstack docs
Blockchain API reference

Start for free

# Game of Battleship Solidity and Hardhat

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.

> Find the article in the Chainstack developer portal []()

## Quick start

Clone the repository:

```sh
git clone https://github.com/chainstacklabs/zk-battleship-game-hardhat.git
```

Install dependencies:

```shell
npm install
```

Run tests:

```shell
npx hardhat test
```

Add environment variables to `.env.sample` and rename to `.env`:

Deploy a node with Chainstack:

1. [Sign up with Chainstack](https://console.chainstack.com/user/account/create).
1. [Deploy a node](https://docs.chainstack.com/platform/join-a-public-network).
1. [View node access and credentials](https://docs.chainstack.com/platform/view-node-access-and-credentials).

> 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.

```env
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](https://faucet.chainstack.com/sepolia-faucet) to get test funds:

Deploy the smart contract:

```sh
npx hardhat run scripts/deploy.ts --network sepolia
```

or

```sh
npx hardhat run scripts/deploy.ts --network goerli
```

Now the contract will be deployed and verified on Etherscan.

## Example response

```sh
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
```