This is a project for the Peer to Peer Systems and Blockchains course of the University of Pisa. The aim of this project is to implement the classic Mastermind game using smart contracts over the Ethereum blockchain.
- Project Structure
- Prerequisites
- How to Deploy the Contract
- How to Run the Sample Frontend Application
- License
The repository is organized as follows:
EtherMind/
├── contracts/
│ ├── EtherMind.sol
│ └── libs/
├── frontend/
├── ignition/
├── scripts/
├── tests/
├── Dockerfile
├── docker-compose.yml
├── hardhat.config.dev.ts
├── hardhat.config.prod.ts
├── hardhat.config.ts
├── Report.pdf
├── README.md
└── ...
- contracts/: contains all the files related to the smart contract implementation.
- EtherMind.sol: is the main file where the smart contract is defined.
- libs/: contains helper functions and structure definitions used in the smart contract.
- frontend/: contains the sample frontend application code and all its dependencies.
- ignition/: contains the script needed to deploy the contract.
- scripts/: contains some scripts needed for the correct working of the docker image.
- tests/: contains all the test' source code that has been used to test the smart contract.
- Dockerfile: Dockerfile for the sample frontend application.
- docker-compose.yml: sample of Docker Compose configuration file that utilizes the above Dockerfile.
- hardhat.config.dev.ts: Hardhat configuration file used for the development and testing of the smart contract.
- hardhat.config.prod.ts: Hardhat configuration file used for the deployment of the production version of the smart contract.
- hardhat.config.ts: is the main Hardhat configuration file, that will include one between the 2 above.
- Report.pdf: a detailed report of our assumptions, implementation decisions, analisys, and user-guide.
- README.md: This document.
In order to develop/compile/test/deploy the smart contract, we assume you have ensure you have the following installed:
Before running the application, ensure you have the following installed:
- Docker
- Docker Compose (Optional, in case you want to try the
docker-compose.yml)
- Download the repo (this can be skipped if you have already downloaded it):
git clone https://github.com/gabrielepongelli/EtherMind
- Enter in the root of the project:
cd EtherMind - Create the
.envfile with the following content:- For the deployment on a local node:
HARDHAT_CONFIG=dev EXTERNAL_NODE=true
- For the deployment on Sepolia:
HARDHAT_CONFIG=prod INFURA_API_KEY=YOUR-INFURA-API-KEY SEPOLIA_PRIVATE_KEY=YOUR-SEPOLIA-PRIVATE-KEY
- For the deployment on a local node:
- Install the project dependencies:
npm install --force
- Compile the contract:
npx hardhat compile
- Deploy it:
- For the deployment on a local node:
npx hardhat ignition deploy ./ignition/modules/EtherMind.ts --network localhost
- For the deployment on Sepolia:
npx hardhat ignition deploy ./ignition/modules/EtherMind.ts --network sepolia
- For the deployment on a local node:
If you don't want to start a local node, skip steps 4-7.
- Download the repo (this can be skipped if you have already downloaded it):
git clone https://github.com/gabrielepongelli/EtherMind
- Enter in the root of the project:
cd EtherMind - Build the docker image:
docker build -t ethermind . - Install the project dependencies:
npm install --force
- Start the local hardhat node:
echo "HARDHAT_CONFIG=dev" >> .env echo "EXTERNAL_NODE=true" >> .env npx hardhat node
- Compile the contract:
npx hardhat compile
- Deploy it on the local node:
npx hardhat ignition deploy ./ignition/modules/EtherMind.ts --network localhost
- Start an instance of the frontend:
Replace to the above command the values:
docker run \ --rm \ -it \ -p PORT:8000 \ -e ETHERMIND_BLOCKCHAIN_PROVIDER_URL="PROVIDER_URL" \ -e ETHERMIND_CONTRACT_ADDRESS="0xCONTRACT_ADDRESS" \ -e ETHERMIND_PRIVATE_KEY="0xONE_OF_THE_PRIVATE_KEYS" \ ethermindPORTwith the port number you want to use.PROVIDER_URLwith the URL of the node to connect (if you want to use a local node, set it tohttp://0.0.0.0:8545).0xCONTRACT_ADDRESSwith the address of the contract starting with0x.0xONE_OF_THE_PRIVATE_KEYSwith the private key of the account you want to use starting with0x.
- Now you can access the web interface from
http://localhost:PORT/, wherePORTis the port number you chosen to use.
Note: if you want to start multiple instances, just repeat this last command changing
PORTandETHERMIND_PRIVATE_KEY.
An example of docker compose file can be seen at /docker-compose.yml.
This project is licensed under the MIT License - see the LICENSE file for details.