Build a Decentralized Voting System on Conflux eSpace Testnet using Solidity

GitHub Repo: VotingDApp on Conflux eSpace
Network: Conflux eSpace Testnet


:globe_with_meridians: 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.


:gear: Key Features

  • :ballot_box: Multiple elections support
  • :man_office_worker: Add candidates per election
  • :white_check_mark: Whitelist-based voter control (optional)
  • :lock: One person, one vote policy
  • :bar_chart: Real-time results and election status
  • :alarm_clock: Time-based election scheduling

:mag: Contract Walkthrough

1. :brain: Struct Definitions

struct Election { ... }
struct Candidate { ... }
  • Election stores metadata such as title, time, and creator.
  • Candidate holds information like name and vote count.

2. :package: 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

:dart: Only the election creator can later manage that election.


3. :heavy_plus_sign: Add Candidates

function addCandidate(...) public onlyElectionCreator { ... }

Candidates must be added before the election starts.


4. :ballot_box: 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. :busts_in_silhouette: Whitelisting Voters

function addToWhitelist(...) public { ... }

Used to restrict election participation to specific addresses. Helpful in internal team or DAO elections.


6. :bar_chart: View Results

function getElectionResults(...) public view returns (...) { ... }

Anyone can view live election results at any time.


7. :closed_lock_with_key: Security with Modifiers

The contract uses modifiers like:

  • onlyOwner
  • onlyElectionCreator
  • electionActive
  • hasNotVoted
  • isWhitelisted

These ensure access control and data integrity.

:tv: Watch the Full Video Tutorial


:bulb: 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.


:link: Links