Welcome to the "Guess the Number" game! This decentralized application (dApp) allows players to guess a secret number on the Core blockchain. The first player to guess the correct number is rewarded with tokens.
- Prerequisites
- Project Structure
- Setup Instructions
- Running the Application
- Interacting with the dApp
- Smart Contract Overview
- Frontend Overview
- Contributing
- License
Before you begin, ensure you have the following installed:
- Node.js (v14 or later)
- npm or Yarn
- MetaMask browser extension
- Basic understanding of Ethereum smart contracts and React
The repository is organized as follows:
contracts/: Contains the Solidity smart contract.scripts/: Deployment scripts for the smart contract.test/: Test scripts for the smart contract.frontend/: React application for the game's frontend.hardhat.config.js: Configuration file for Hardhat.
-
Clone the Repository
git clone https://github.com/coredao-org/dapp-tutorial.git cd dapp-tutorial/08-Guess-Game -
Install Dependencies
Navigate to the root directory and install the necessary packages:
npm install
Then, navigate to the
frontenddirectory and install its dependencies:cd frontend npm install
-
Compile the Smart Contract
Return to the root directory and compile the contract:
cd .. npx hardhat compile -
Deploy the Smart Contract
Deploy the contract to the Core blockchain testnet:
npx hardhat run scripts/deploy.js --network coreTestnet
Ensure you have configured the
coreTestnetnetwork in yourhardhat.config.jswith the appropriate RPC URL and account details. -
Start the Frontend Application
Navigate back to the
frontenddirectory and start the React application:cd frontend npm run devThe application will be available at
http://localhost:3000.
-
Connect Wallet
- Open the application in your browser.
- Click on the "Connect Wallet" button.
- Approve the connection in your MetaMask extension.
-
Make a Guess
- Enter a number between 1 and 100 in the input field.
- Click the "Guess" button.
- The application will inform you if your guess is too high, too low, or correct.
- Your number of attempts will be displayed.
-
Reset the Game
- Click the "New Game" button to reset the game and start over.
The smart contract is written in Solidity and is located in the contracts directory. It manages the game's logic, including:
- Storing the secret number.
- Tracking the number of attempts by each player.
- Rewarding the first player who guesses the correct number.
The frontend is built with React and is located in the frontend directory. It interacts with the smart contract using the ethers.js library and provides a user-friendly interface for players.
Contributions are welcome! Please fork the repository and submit a pull request with your changes.