Skip to content

About

Majority voting contract

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

55 Commits

Folders and files

Repository files navigation

Majority voting contract

The majority voting system is a way of determining the election results, in which the candidate who obtains the majority of votes prescribed by law is considered elected. The majority system has three main subspecies: A relative majority. The candidate who has more support than others wins. An absolute majority. A candidate for victory must receive more than 50% of the votes (that is, 50% + one vote). If no politician crosses this threshold in the first round, a second round of voting is called. It usually involves two candidates who were the most popular in the first. Qualified majority. The candidate must receive a minimum number of votes (usually significantly more than half). The feature of the majority system is the territorial division of the country into districts or districts, each of which has the right to choose one representative. In essence, it is a voting system according to the principle of «winner take all» (or «winner takes all»). An electoral bloc can win all seats in a legislative body or constituency by denying representation to any political minority. Such systems are used in many large democracies. Such systems are sometimes called «majoritarian representation». Most such systems do not always elect candidates who prefer a majority, and do not always identify the winners who have received the majority of votes in the district.

This is a solid example of a structured voting dApp. It’s a version of the contract compatible with Solidity 0.8.20, including: safe use of pragma abicoder v2; added SafeCast if needed in future. I use Hardhat and Waffle to write tests for registration flow, proposal registration, voting, tallying, access control and stage transitions. Next step is deploy to a Testnet (e.g., Sepolia). Let's get ETH from faucet. Then go to https://sepoliafaucet.com/. And request ETH for your wallet address (use MetaMask or similar). I'd like to create a simple frontend DApp to interact with SimpleVoting.sol smart contract. What I Build: A basic React + Ethers.js voting DApp that allows users to: view current workflow status; register voters (admin only); submit proposals; vote on proposals; end phases and tally votes; view results. I’ll assume you’ve already upgraded the contract to Solidity 0.8.20 and deployed it to a testnet like Sepolia.

Step 1. Setup Frontend with Vite + React:

cd voting-dapp
mkdir frontend && cd frontend
npm create vite@latest . --template react
npm install

Install required dependencies:

npm install ethers @metamask/detect-provider

Step 2. Add Contract ABI.

After deploying your contract, copy its ABI from:

artifacts/contracts/SimpleVoting.sol/SimpleVoting.json

Create a file in your frontend:

src/utils/contractAbi.js

Step 3. Create Web3 Hook:

src/hooks/useVotingContract.js

Step 4. UI Components:

We’ll now build modular components for each action.

Component 1. Connect Wallet & Display Status:

src/components/StatusDisplay.jsx;

Component 2. Admin – Register Voter:

src/components/VoterRegistration.jsx;

Component 3. Submit Proposal:

src/components/ProposalRegistration.jsx;

Component 4. Vote:

src/components/Vote.jsx;

Component 5. Tally Votes:

src/components/Results.jsx;

Final App Layout:

src/App.jsx;

Step 5: Run the DApp

Start the dev server:

npm run dev

Open in browser: http://localhost:5173 Connect MetaMask and start interacting with majority voting contract.

Optional Enhancements:

  1. Proposal List: Show all registered proposals dynamically;
  2. Voting History: Show user's previous vote;
  3. Phase Controls: Buttons to move through workflow stages;
  4. Winner Display: Show winning proposal after tally;
  5. Toast Notifications: Use react-toastify or similar for UX.

About

Majority voting contract

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages