Build a secure e-voting app

Get the code View the demo Run the app Code walkthrough 1 Code walkthrough 2

Summary

With its distributed ledger, smart contracts, and non-repudiation capabilities, blockchain is revolutionizing the way organizations do business, and the election industry is no exception. This developer code pattern shows you how to implement a web-based blockchain app using the IBM Blockchain Platform to facilitate voting and help ensure the prevention of double-voting.

Description

Have you ever wondered how exactly the votes in a presidential election are counted? What if — instead of having volunteers spending many hours each day manually counting votes — you had an app backed by blockchain, recording each voter’s vote, ensuring that double-voting is not possible? That’s what this code pattern explains how to do. We aim to build a web app in which the voter can register with their driver’s license, get a unique voter ID, which is used to log in to the app, and cast the vote. The vote is tallied on the blockchain, and the web app shows the current poll standings.

At the start of the application, the user registers to vote by providing a driver’s license number, registrar district, and first and last name. In this step, you can check to see if the driver’s license is valid and has not been registered previously. If all goes well, you create a private and public key for the voter with the certificate authority running on the cloud and add those keys to the wallet.

After that, users use their driver’s license numbers to submit votes, during which the application checks to see if the driver with this license number has voted before. If this particular license number has not been used before, the vote goes through the consensus policy, and the world state is updated. The application then updates the current election standings to show which political party the user has voted for.

Since each transaction submitted to the ordering service must have a signature from a valid public-private key pair, you can trace back each transaction to a registered voter of the application, in case of an audit.

Given that every transaction that has been recorded on the blockchain has reached consensus on the network and is immutable, using blockchain for voting can help ensure trust between the public and the government. In addition, by using smart contracts to automate the tallying of votes, voting becomes a much more secure and cost-effective process. Although this is a simple application, you can see how to implement a Hyperledger Fabric web app to decrease the chance of election fraud and enhance a voting application by using blockchain technology.

Flow

flow

  1. The blockchain operator sets up the IBM Blockchain Platform service.
  2. IBM Blockchain Platform creates a Hyperledger Fabric network on an IBM Kubernetes Service, and the operator installs and instantiates the smart contract on the network.
  3. The Node.js app server uses the Fabric SDK to interact with the deployed network on IBM Blockchain Platform and creates APIs for a web client.
  4. The Vue.js client uses the Node.js application API to interact with the network.
  5. The user interacts with the Vue.js web interface to cast their ballot and query the world state to see current poll standings.

Instructions

Ready to get started? Check out the README for the step-by-step details on:

  1. Cloning the repo
  2. Creating IBM Cloud™ services
  3. Building a network
  4. Deploying a voterContract smart contract on the network
  5. Connecting the app to the network
  6. Running the application