A simple example of a Voting System smart contract deployed and interacted with using Hardhat and ethers.js.
Before you begin, ensure you have the following installed:
-
Clone the repository and navigate to the project folder.
-
Install project dependencies:
npm install
-
Compile the smart contract:
npx hardhat compile
-
Deploy the smart contract:
npx hardhat run scripts/deploy.js --network <network-name>
-
Execute the script that interacts with the smart contract:
npx hardhat run scripts/votingSystem.js --network <network-name>
-
Execute tests:
npx hardhat test
Example of deploying and interacting with the smart contract on a local node:
-
Start a Hardhat node:
npx hardhat node
-
On a different terminal execute the deploy script:
npx hardhat run scripts/deploy.js --network localhost
output:
Deploying contracts with the account: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 VotingSystem deployed to: 0x0165878A594ca255338adfa4d48449f69242Eb8F
-
Execute the interaction script:
npx hardhat run scripts/votingSystem.js --network localhost
output:
Candidate CandidateA added Candidate CandidateB added Voting started Voting ended Winner: CandidateB
This demonstrates how to deploy, interact with, and test the Voting System smart contract in a local development environment.