Crypto Consensus is a decentralized voting application built using Solidity, Hardhat, and Next.js. It allows the contract owner to register voters, voters to submit proposals, and participants to vote on these proposals.
Before you begin, ensure you have met the following requirements:
- Node.js (version 14 or later)
- npm or yarn
- MetaMask (or any other Ethereum wallet)
Follow these steps to install and set up the project locally:
-
Clone the Repository
git clone https://github.com/MichaelOrts/Project3-Voting.git cd Project3-Voting -
Install Dependencies
# Using npm npm install # Or using yarn yarn install
-
Install Hardhat
# Using npm npm install --save-dev hardhat # Or using yarn yarn add --dev hardhat
-
Create Environment Files
Create a
.envfile in the root directory of your project and add the following variables:PRIVATE_KEY=your_private_key INFURA_PROJECT_ID=your_infura_project_id
-
Compile the Contracts
Compile the smart contracts using Hardhat:
npx hardhat compile
-
Deploy the Contracts
Deploy the smart contracts to your local Hardhat network:
npx hardhat node
In a new terminal window, deploy the contracts:
npx hardhat run scripts/deploy.js --network localhost
-
Update Contract Address
Copy the deployed contract address and update the
frontend/constant/index.jsfile:export const contractAddress = "your_deployed_contract_address"; export const contractAbi = [ /* ABI from your compiled contract */ ];
-
Start the Local Hardhat Node
If not already running, start the Hardhat node:
npx hardhat node
-
Run the Next.js Application
Start the Next.js application:
npm run dev
or
yarn dev
The application should now be running on
http://localhost:3000.
To run the tests, use the following command:
npx hardhat testEnsure that your contracts are compiled and the Hardhat node is running.
-
Connect MetaMask
-
Open MetaMask and connect to the local Hardhat network (usually http://127.0.0.1:8545).
-
Import an account using one of the private keys provided by Hardhat.
-
-
Interact with the DApp
- As the contract owner, you can register voters.
- Registered voters can submit proposals.
- Voters can vote on proposals once the voting session starts.
If you encounter any issues, feel free to open an issue on the repository or consult the documentation for Hardhat and Next.js.