GitHub Repo: VotingDApp on Conflux eSpace
Network: Conflux eSpace Testnet
Introduction
Decentralized voting applications are a powerful use case for blockchain technology. In this tutorial, we explore a Solidity-based Voting DApp deployed on the Conflux eSpace Testnet.
We’ll walk through the core functionalities of the contract and how it empowers election creators to conduct transparent, tamper-proof voting.
Key Features
-
Multiple elections support
-
Add candidates per election
-
Whitelist-based voter control (optional)
-
One person, one vote policy
-
Real-time results and election status
-
Time-based election scheduling
Contract Walkthrough
1.
Struct Definitions
struct Election { ... }
struct Candidate { ... }
- Election stores metadata such as title, time, and creator.
- Candidate holds information like name and vote count.
2.
Election Creation
function createElection(...) public returns (uint256) { ... }
Election creators can launch a new election by specifying:
- Title and description
- Start and end times (as UNIX timestamps)
- Option to enable a whitelist
Only the election creator can later manage that election.
3.
Add Candidates
function addCandidate(...) public onlyElectionCreator { ... }
Candidates must be added before the election starts.
4.
Cast a Vote
function castVote(...) public { ... }
Voting is only allowed if:
- The election is active and ongoing
- The voter hasn’t voted yet
- (If enabled) The voter is on the whitelist
5.
Whitelisting Voters
function addToWhitelist(...) public { ... }
Used to restrict election participation to specific addresses. Helpful in internal team or DAO elections.
6.
View Results
function getElectionResults(...) public view returns (...) { ... }
Anyone can view live election results at any time.
7.
Security with Modifiers
The contract uses modifiers like:
onlyOwner
onlyElectionCreator
electionActive
hasNotVoted
isWhitelisted
These ensure access control and data integrity.
Watch the Full Video Tutorial
Conclusion
With this Voting DApp, we’ve demonstrated how to bring transparency and trust into elections using blockchain. The Conflux eSpace Testnet offers a fast and EVM-compatible environment that’s perfect for experimentation and learning.
Links
-
GitHub Repo: VotingDApp Contract
-
Conflux eSpace Docs: Get Started
-
Follow Me: @Vikash_8090_b