Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 65

VOTING USING BLOCKCHAIN

TECHNOLOGY

Ganesh
Class :- Tybsc(cs)
Roll no :- 1952009
0|Page
A
PROJECT REPORT

ON

VOTING USING BLOCKCHAIN TECHNOLOGY


UNDER THE PARTIAL FULFILMENT OF UNIVERSITY OF

MUMBAI REQUIREMENT FOR THE COURSE OF

TYBSC(COMPUTER SCIENCE)

-: SUBMITTED BY :-

MR. GANESH SANTOSH GUPTA


-: GUIDED BY :-
Prof. NISHA KOTHAWADE

DEPARTMENT OF COMPUTER SCIENCE


VPM’S RAMNIKLAL Z SHAH COLLEGE OF ARTS SCIENCE
&
COMMERCE
MULUND (EAST), MUMBAI-400-081
UNIVERSITY OF MUMBAI
2019-2020.

1|Page
CERTIFICATE

This is to certify that the project entitled VOTING USING BLOCKCHAIN TECHNOLOGY
Undertaken at the VPM’s R.Z. Shah College of Arts , Science and Commerce by Mr.
GANESH GUPTA Seat no. 1952009 in partial fulfillment of B.Sc. CS degree (Semester- V)
Examination had not been submitted for any other examination and does not form part of
any other course undergone by the candidate.
It is further certified that he has completed all required phases of the project.

Signature of Internal Guide Signature

HOD / In-charge / Coordinator

Signature of the External

2|Page
Declaration

I , GANESH GUPTA , student of VPM R.Z. Shah College of Arts, Science & Commerce
Mithagar Road, Mulund(E), Mumbai-81, studying in TY BSC COMPUTER SCIENCE
hereby declare that I have completed this project on VOTING USING BLOCKCHAIN
TECHNOLOGY during the academic year 2018-2019.

The information submitted is true and original to the best of my knowledge.

Date:

Place:

GANESH GUPTA

BSC in (USING BLOCKCHAIN


TECHNOLOGY)

3|Page
index
Sr.no. Title Page No.
01 Acknowledgement 5
02 Overview
2.1 Abstract 6
2.2 Undertaking 7
2.3 Objective 8
2.4 Introduction 9

2.5 Requirement Specification 10

2.6 Feasibility Study 13

03 System Design
3.1 E-R Diagram 16

3.2 Class Diagram 17

3.3 Use Case Diagram 18

3.4 System Flow Chart 20

04 Code Implementation 21

05 Results
5.1 Tables 60

5.2 Screen Shots 61

06 Reference and Bibliography 64

4|Page
ACKNOWLEDGEMENT

It gives great pleasure and pride as I presented my project on “VOTING USING

BLOCKCHAIN TECHNOLOGY”. This acknowledgement is a small effort to


express and our gratitude to all those who have shown me the path to bring out
the various colours of this project with their vast treasure of experience and
knowledge.

I would like to express my sincere thanks to Prof. Mrs. Nisha kothawade , who helps
me throughout the project for providing me moral support, conductive work
environment and the much needed inspiration to conclude this project on time.

I also take this opportunity to thank Head of the Department Mrs.Rajashree Prabhu
and thanks to all of our professors of the Department of Computer Science of
V.P.M.RZ SHAH College for giving me an opportunity to study in the institute and
the most needed guidance throughout the duration of the course

Prof. Mrs. Nisha kothavade has provided me with the guidance and necessary
support during each phase of the project. He was the Source of continuous
encouragement as each milestone was crossed.

Last but not the least, I would like to thank my friends and family for the support
and encouragement they given me during this course of work.

5|Page
ABSTRACT

Cryptocurrencies are being used widely and gaining popularity. The main theme
of all cryptocurrencies are a transfer of value between two peers without needing
a central authority, such as a bank or financial institution; it is distributed and
decentralized. Blockchain is a technology behind all cryptocurrencies. It’s a
constantly growing ledger that keeps a permanent record of all the transactions
that have taken place, in a secure, chronological and immutable way that makes
peer to peer value transfer possible. Value can be anything. In the case of
cryptocurrencies, it takes the meaning of money. Whereas in gaming it can take
the form of points. In electoral voting, the value can take the form of a vote. In
this paper, we will show how blockchain can be used to transfer votes between
two peers. In our case, one peer is the voter and the other is the candidate who
receives the vote. We will explain how blockchain can be employed in mass
electoral voting procedures in a more secure way without needing a central
authority body. We will explain a voting system using blockchain that is more
robust, tamperproof (immutable to voting changes either by the voter or by any
other third parties) and costeffective. We have reviewed various blockchain
technologies, i.e. Ethereum, Multichain, available today to use in our voting
system. Also, we will elaborate on the architecture, design and design constraints
and implementation implications of such a voting mechanism in our society

6|Page
UNDERTAKING

This is to declare that the project entitled “VOTING USING BLOCKCHAIN

TECHNOLOGY” is an original work done by the undersigned, in partial fulfilment


of the requirement for the degree

“ Bachelor of Science in Computer Science ” at CS Department, VPM’S

RAMNIKLAL Z SHAH COLLEGE .All the analysis design and System developed
have been accomplished by the

undersigned. Moreover, this project has not been submitted to any other College or

University.

Mr. Ganesh Santosh Gupta

7|Page
OBJECTIVE
 To study the different aspects of Blockchain.

 To study how concept of Blockchain can help a country.

 Voting using is a new technology which can be used for E-voting purpose so
that a user can easily vote using the internet.

 Easy to use and efficient way for voting.

 To reduce the efforts of people for voting prevents them to stand in long que to
vote.

 Digital voting is the use of electronic devices, such as voting machines or an


internet browser, to cast votes.

 A user can easily vote with the help of given address provided him to vote.

 Here there is no chance for mix of votes or any kind of interruption because
of use of blockchain.

8|Page
INTRODUCTION

Democratic voting is a crucial and serious event in any country. The most common
way in which a country votes is through a paper based system, but is it not time to
bring voting into the 21st century of modern technology?

Digital voting is the use of electronic devices, such as voting machines or an


internet browser, to cast votes. These are sometimes referred to as e-voting when
voting using a machine in a polling station, and i-voting when using a web browser.

Security of digital voting is always the biggest concern when considering to


implement a digital voting system. With such monumental decisions at stake, there
can be no doubt about the system’s ability to secure data and defend against
potential attacks. One way the security issues can be potentially solved is through
the technology of blockchains.

Blockchain technology originates from the underlying architectural design of the


cryptocurrency bitcoin. It is a form of distributed database where records take the
form of transactions, a block is a collection of these transactions.

With the use of blockchains a secure and robust system for 4 digital voting can be
devised. This report outlines our idea of how blockchain technology could be used
to implement a secure digital voting system.

9|Page
REQUIREMENT SPECIFICATION
A Software Requirement Specification (SRS) is a description of a software

system to be developed . It lays out functional and non-functional

requirements, and may include a set of use cases that describe the user

interactions that the software must provide.

SOFTWARE REQUIREMNTS :-

Front End :- chrome(node js, html, javascript )

Back End :- ganache(database)

Development Tool :- visual studio code , metamask

HARDWARE REQUIREMENTS :-

Processor :- Intel i3/AMD


DISK Space :- 1GB
RAM :- 4GB
DESKTOP/ LAPTOP

FUNCTIONAL REQUIREMENT :-

ADMIN :-

Login : The Admin can Login to start voting.


Management : The admin manages two functions.

1. START VOTING :-

Only the can Admin Start the voting .

10 | P a g e
2. TIME SELCTION :-

Admin can decide that till when the voting will can be done by using the
stopwatch function.

CANDIDATES :-

Candidates can start voting once they have got the id (eg:metamask)

11 | P a g e
NON-FUCTIONAL REQUIREMENT :-

Current Digital Voting Systems:

A number of digital voting systems are currently in use in countries around the
world. We researched some of these systems to familiarise ourselves with current
implementations, particularly Estonia. Estonia has had electronic voting since 2005
and in 2007 was the first country in the world to allow online voting. In the 2015
parliamentary election 30.5% of all votes were made though the nation’s i-voting
system (Vabariigi Valimiskomisjon, 2016). The bases of this system is the national
ID card that all Estonian citizens are given. These cards contain encrypted files that
identify the owner and allows the owner to carry out a number of online and
electronic activities including online banking services, digitally signing documents,
access their information on government databases and i-voting. (Electronic ID Card,
no date)

 The system should be user friendly.


 The system should be accurate.

Security

 The database is fully secure as it uses the blockchain technique which is a


most secure type of storing the data.

Availability

 This service will we available for every people who is eligible for voting .

12 | P a g e
FEASIBLITY STUDY

Feasibility study includes consideration of all the possible way to provide

solution to the given problem. The proposed solution should satisfy all the user

requirements and should be flexible enough so that future changes can be

easily done based on the future requirements.

OPERATIONAL FEASIBILTY

Operation of the proposed system depend on the it’s user. These various user type

are mentioned below:

1. Admin

2. Candidates

Admin :-
 Admin can manage the Enrollment of the candidate.
 If the user is not in the voting criteria then he or she cannot
vote.
 Admin can provide necessary information related to the websites
update .
 Admin can select the time for voting should be done.

13 | P a g e
Candidates :-
 Candidate gets an ID for voting.
 Candidates can vote once eligible for voting.

TECHNICAL FEASIBLITY

 Voting using blockchain is created by using certain programming


languages like NODEJS , SOLIDITY, XML& GANACHE as a
database.
 SOLIDITY is used for front-end and XML for data transfer.
 This system avoids manual work such as voting using the paper system
to vote.
 This technique stores the data in a centralized way which is stored on
different blocks of blockchain to safeguard the data.

ECONOMICAL FEASIBLITY
 As no papers are required so it reduce cost.

 It would be beneficial because only one time development efforts


required.

14 | P a g e
All people who knows to use internet can easily use this type of voting so no
special skills required to run the system.

15 | P a g e
SYSTEM DESIGN

E-R DIAGRAM

NAME

ELECTION
ADMIN
ID CANDIDATE

PASSWORD
ID

MEMBERS
VOTE
VOTER
DETAILS

VOTE ID

ID
VOTE COUNT

16 | P a g e
CLASS DIAGRAM :-

ADMIN
+ID : INTEGER
+PASSWORD: STRING

VOTER
+ID: INTEGER VOTING DETAILS
+MEMBER: VARCHAR
+VOTE ID: INTEGER
+VOTE COUNT: INTEGER

CANDIDATES
+NAME: VARCHAR
+ID: INTEGER

17 | P a g e
USE CASE DIAGRAM :-

ADMIN

CAN START
VOTING

END VOTING

VIEW VOTING
DETAILS

18 | P a g e
USER

VOTE

ENROLL FOR
VOTING

VIEW RESULT
OF VOTE

19 | P a g e
SYSTEM FLOW CHART:-

20 | P a g e
CODE :-

Election:-

pragma solidity ^0.5.0;

/**

* The Election contract does this and that...

*/

contract Election {

//model

//store

//fetch

struct Candidate {

uint id;

bytes32 name;

uint voteCount;

bool public electionStarted;

mapping (address => bool) public voters;

mapping (uint => Candidate) public candidates;

uint public candidatesCount;

string public time;

// uint public min;

constructor () public {

21 | P a g e
electionStarted = false;

/*candidateList = _candidateNames;

for(uint i =0;i<candidateList.length;i++){

addCandidate(candidateList[i]);*/

//}

//addCandidate(candidate);

function addCandidate (bytes32 _name) public {

require (msg.sender ==
address(0x003a9ce4cd5f1dbd38a8e13a7fa042be2334b81d3f),

"Sender not authorised");

require (!electionStarted,"Election is going on");

require (isNewEntry(_name),"Already exists");

candidatesCount ++;

candidates[candidatesCount] = Candidate(candidatesCount,_name,0);

function vote (uint candidateId) public {

require (!voters[msg.sender],"Already voted");

22 | P a g e
require (candidateId>0&&candidateId<=candidatesCount,"Invalid
candidate ID");

candidates[candidateId].voteCount++;

voters[msg.sender] = true;

function isNewEntry(bytes32 candidate) public view returns (bool) {

for(uint i = 1; i <= candidatesCount; i++) {

if (candidates[i].name == candidate) {

return false;

return true;

function startVote () public {

require (msg.sender ==
address(0x0038b9D8EE6ba24c2D2a07cb8395478E93F086F9B5),"Not
authorized");

electionStarted = true;

function setTimer (string memory a) public {

23 | P a g e
require (msg.sender ==
address(0x0038b9D8EE6ba24c2D2a07cb8395478E93F086F9B5),"Not
authorized");

time = a;

function getTimer () public view returns(string memory) {

return time;

function gethighest () public view returns(uint) {

require (candidatesCount>0,"invalid candidate");

Candidate memory max = candidates[1];

for (uint i = 2;i<=candidatesCount;i++){

if(candidates[i].voteCount>max.voteCount){

max = candidates[i];

return max.id;

24 | P a g e
Migrations:-

pragma solidity ^0.5.0;

contract Migrations {

address public owner;

uint public last_completed_migration;

modifier restricted() {

if (msg.sender == owner) _;

constructor() public {

owner = msg.sender;

function setCompleted(uint completed) public restricted {

last_completed_migration = completed;

function upgrade(address new_address) public restricted {

Migrations upgraded = Migrations(new_address);

upgraded.setCompleted(last_completed_migration);

}
25 | P a g e
}

Array:-

"_args": [

"array-unique@0.3.2",

"C:\\Users\\Nilam\\Documents\\Election"

],

"_development": true,

"_from": "array-unique@0.3.2",

"_id": "array-unique@0.3.2",

"_inBundle": false,

"_integrity": "sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg=",

"_location": "/array-unique",

"_phantomChildren": {},

"_requested": {

"type": "version",
26 | P a g e
"registry": true,

"raw": "array-unique@0.3.2",

"name": "array-unique",

"escapedName": "array-unique",

"rawSpec": "0.3.2",

"saveSpec": null,

"fetchSpec": "0.3.2"

},

"_requiredBy": [

"/braces",

"/extglob",

"/micromatch",

"/nanomatch"

],

"_resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.3.2.tgz",

"_spec": "0.3.2",

"_where": "C:\\Users\\Nilam\\Documents\\Election",

"author": {

"name": "Jon Schlinkert",

"url": "https://github.com/jonschlinkert"

},

"bugs": {

"url": "https://github.com/jonschlinkert/array-unique/issues"
27 | P a g e
},

"description": "Remove duplicate values from an array. Fastest ES5


implementation.",

"devDependencies": {

"array-uniq": "^1.0.2",

"benchmarked": "^0.1.3",

"gulp-format-md": "^0.1.9",

"mocha": "^2.5.3",

"should": "^10.0.0"

},

"engines": {

"node": ">=0.10.0"

},

"files": [

"index.js",

"LICENSE",

"README.md"

],

"homepage": "https://github.com/jonschlinkert/array-unique",

"keywords": [

"array",

"unique"

],

28 | P a g e
"license": "MIT",

"main": "index.js",

"name": "array-unique",

"repository": {

"type": "git",

"url": "git+https://github.com/jonschlinkert/array-unique.git"

},

"scripts": {

"test": "mocha"

},

"verb": {

"toc": false,

"layout": "default",

"tasks": [

"readme"

],

"plugins": [

"gulp-format-md"

],

"related": {

"list": [

"arr-diff",

"arr-union",
29 | P a g e
"arr-flatten",

"arr-reduce",

"arr-map",

"arr-pluck"

},

"reflinks": [

"verb",

"verb-generate-readme"

],

"lint": {

"reflinks": true

},

"version": "0.3.2"

30 | P a g e
Set blocking:-

"_args": [

"set-blocking@2.0.0",

"C:\\Users\\Nilam\\Documents\\Election"

],

"_development": true,

"_from": "set-blocking@2.0.0",

"_id": "set-blocking@2.0.0",

"_inBundle": false,

"_integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=",

"_location": "/set-blocking",

"_phantomChildren": {},

"_requested": {

"type": "version",

"registry": true,

"raw": "set-blocking@2.0.0",

"name": "set-blocking",

"escapedName": "set-blocking",

"rawSpec": "2.0.0",

31 | P a g e
"saveSpec": null,

"fetchSpec": "2.0.0"

},

"_requiredBy": [

"/localtunnel/yargs",

"/yargs"

],

"_resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",

"_spec": "2.0.0",

"_where": "C:\\Users\\Nilam\\Documents\\Election",

"author": {

"name": "Ben Coe",

"email": "ben@npmjs.com"

},

"bugs": {

"url": "https://github.com/yargs/set-blocking/issues"

},

"description": "set blocking stdio and stderr ensuring that terminal output does
not truncate",

"devDependencies": {

"chai": "^3.5.0",

"coveralls": "^2.11.9",

32 | P a g e
"mocha": "^2.4.5",

"nyc": "^6.4.4",

"standard": "^7.0.1",

"standard-version": "^2.2.1"

},

"files": [

"index.js",

"LICENSE.txt"

],

"homepage": "https://github.com/yargs/set-blocking#readme",

"keywords": [

"flush",

"terminal",

"blocking",

"shim",

"stdio",

"stderr"

],

"license": "ISC",

"main": "index.js",

"name": "set-blocking",

"repository": {

33 | P a g e
"type": "git",

"url": "git+https://github.com/yargs/set-blocking.git"

},

"scripts": {

"coverage": "nyc report --reporter=text-lcov | coveralls",

"pretest": "standard",

"test": "nyc mocha ./test/*.js",

"version": "standard-version"

},

"version": "2.0.0"

Client:-

"_args": [

"socket.io-client@2.2.0",

"C:\\Users\\Nilam\\Documents\\Election"

34 | P a g e
]

],

"_development": true,

"_from": "socket.io-client@2.2.0",

"_id": "socket.io-client@2.2.0",

"_inBundle": false,

"_integrity": "sha512-
56ZrkTDbdTLmBIyfFYesgOxsjcLnwAKoN4CiPyTVkMQj3zTUh0QAx3GbvIvLpFEOvQ
Wu92yyWICxB0u7wkVbYA==",

"_location": "/socket.io-client",

"_phantomChildren": {},

"_requested": {

"type": "version",

"registry": true,

"raw": "socket.io-client@2.2.0",

"name": "socket.io-client",

"escapedName": "socket.io-client",

"rawSpec": "2.2.0",

"saveSpec": null,

"fetchSpec": "2.2.0"

},

"_requiredBy": [

35 | P a g e
"/browser-sync-ui"

],

"_resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-
2.2.0.tgz",

"_spec": "2.2.0",

"_where": "C:\\Users\\Nilam\\Documents\\Election",

"bugs": {

"url": "https://github.com/Automattic/socket.io-client/issues"

},

"contributors": [

"name": "Guillermo Rauch",

"email": "rauchg@gmail.com"

},

"name": "Arnout Kazemier",

"email": "info@3rd-eden.com"

},

"name": "Vladimir Dronnikov",

"email": "dronnikov@gmail.com"

},

36 | P a g e
{

"name": "Einar Otto Stangvik",

"email": "einaros@gmail.com"

],

"dependencies": {

"backo2": "1.0.2",

"base64-arraybuffer": "0.1.5",

"component-bind": "1.0.0",

"component-emitter": "1.2.1",

"debug": "~3.1.0",

"engine.io-client": "~3.3.1",

"has-binary2": "~1.0.2",

"has-cors": "1.1.0",

"indexof": "0.0.1",

"object-component": "0.0.3",

"parseqs": "0.0.5",

"parseuri": "0.0.5",

"socket.io-parser": "~3.3.0",

"to-array": "0.1.4"

},

37 | P a g e
"description": "[![Build Status](https://secure.travis-ci.org/socketio/socket.io-
client.svg?branch=master)](http://travis-ci.org/socketio/socket.io-client)
[![Dependency Status](https://david-dm.org/socketio/socket.io-
client.svg)](https://david-dm.org/socketio/socket.io-client) [![devDependency
Status](https://david-dm.org/socketio/socket.io-client/dev-
status.svg)](https://david-dm.org/socketio/socket.io-
client#info=devDependencies) [![NPM version](https://badge.fury.io/js/socket.io-
client.svg)](https://www.npmjs.com/package/socket.io-client)
![Downloads](http://img.shields.io/npm/dm/socket.io-client.svg?style=flat)
[![](http://slack.socket.io/badge.svg?)](http://slack.socket.io)",

"devDependencies": {

"babel-core": "^6.24.1",

"babel-eslint": "4.1.7",

"babel-loader": "7.0.0",

"babel-preset-es2015": "6.24.1",

"concat-stream": "^1.6.0",

"derequire": "^2.0.6",

"eslint-config-standard": "4.4.0",

"eslint-plugin-standard": "1.3.1",

"expect.js": "0.3.1",

"gulp": "^3.9.1",

"gulp-eslint": "1.1.1",

"gulp-file": "^0.3.0",

"gulp-istanbul": "^1.1.1",

"gulp-mocha": "^4.3.1",

38 | P a g e
"gulp-task-listing": "1.0.1",

"imports-loader": "^0.7.1",

"istanbul": "^0.4.5",

"mocha": "^3.3.0",

"socket.io": "2.2.0",

"socket.io-browsers": "^1.0.0",

"strip-loader": "0.1.2",

"text-blob-builder": "0.0.1",

"webpack-merge": "4.1.2",

"webpack-stream": "3.2.0",

"zuul": "~3.11.1",

"zuul-builder-webpack": "^1.2.0",

"zuul-ngrok": "4.0.0"

},

"files": [

"lib/",

"dist/"

],

"homepage": "https://github.com/Automattic/socket.io-client#readme",

"keywords": [

"realtime",

"framework",

39 | P a g e
"websocket",

"tcp",

"events",

"client"

],

"license": "MIT",

"main": "./lib/index",

"name": "socket.io-client",

"repository": {

"type": "git",

"url": "git+https://github.com/Automattic/socket.io-client.git"

},

"scripts": {

"test": "gulp test"

},

"version": "2.2.0"

40 | P a g e
String:-

/*!

* split-string <https://github.com/jonschlinkert/split-string>

* Copyright (c) 2015-2017, Jon Schlinkert.

* Released under the MIT License.

*/

'use strict';

var extend = require('extend-shallow');

module.exports = function(str, options, fn) {

if (typeof str !== 'string') {

throw new TypeError('expected a string');

if (typeof options === 'function') {

fn = options;

options = null;

41 | P a g e
// allow separator to be defined as a string

if (typeof options === 'string') {

options = { sep: options };

var opts = extend({sep: '.'}, options);

var quotes = opts.quotes || ['"', "'", '`'];

var brackets;

if (opts.brackets === true) {

brackets = {

'<': '>',

'(': ')',

'[': ']',

'{': '}'

};

} else if (opts.brackets) {

brackets = opts.brackets;

var tokens = [];

var stack = [];

42 | P a g e
var arr = [''];

var sep = opts.sep;

var len = str.length;

var idx = -1;

var closeIdx;

function expected() {

if (brackets && stack.length) {

return brackets[stack[stack.length - 1]];

while (++idx < len) {

var ch = str[idx];

var next = str[idx + 1];

var tok = { val: ch, idx: idx, arr: arr, str: str };

tokens.push(tok);

if (ch === '\\') {

tok.val = keepEscaping(opts, str, idx) === true ? (ch + next) : next;

tok.escaped = true;

if (typeof fn === 'function') {

43 | P a g e
fn(tok);

arr[arr.length - 1] += tok.val;

idx++;

continue;

if (brackets && brackets[ch]) {

stack.push(ch);

var e = expected();

var i = idx + 1;

if (str.indexOf(e, i + 1) !== -1) {

while (stack.length && i < len) {

var s = str[++i];

if (s === '\\') {

s++;

continue;

if (quotes.indexOf(s) !== -1) {

i = getClosingQuote(str, s, i + 1);

44 | P a g e
continue;

e = expected();

if (stack.length && str.indexOf(e, i + 1) === -1) {

break;

if (brackets[s]) {

stack.push(s);

continue;

if (e === s) {

stack.pop();

closeIdx = i;

if (closeIdx === -1) {

arr[arr.length - 1] += ch;

45 | P a g e
continue;

ch = str.slice(idx, closeIdx + 1);

tok.val = ch;

tok.idx = idx = closeIdx;

if (quotes.indexOf(ch) !== -1) {

closeIdx = getClosingQuote(str, ch, idx + 1);

if (closeIdx === -1) {

arr[arr.length - 1] += ch;

continue;

if (keepQuotes(ch, opts) === true) {

ch = str.slice(idx, closeIdx + 1);

} else {

ch = str.slice(idx + 1, closeIdx);

tok.val = ch;

46 | P a g e
tok.idx = idx = closeIdx;

if (typeof fn === 'function') {

fn(tok, tokens);

ch = tok.val;

idx = tok.idx;

if (tok.val === sep && tok.split !== false) {

arr.push('');

continue;

arr[arr.length - 1] += tok.val;

return arr;

};

function getClosingQuote(str, ch, i, brackets) {

var idx = str.indexOf(ch, i);

47 | P a g e
if (str.charAt(idx - 1) === '\\') {

return getClosingQuote(str, ch, idx + 1);

return idx;

function keepQuotes(ch, opts) {

if (opts.keepDoubleQuotes === true && ch === '"') return true;

if (opts.keepSingleQuotes === true && ch === "'") return true;

return opts.keepQuotes;

function keepEscaping(opts, str, idx) {

if (typeof opts.keepEscaping === 'function') {

return opts.keepEscaping(str, idx);

return opts.keepEscaping === true || str[idx + 1] === '\\';

48 | P a g e
Js:-

App = {

web3Provider: null,

contracts: {},

account: '0x0',

init: function() {

return App.initWeb3();

},

initWeb3: function() {

// TODO: refactor conditional

if (typeof web3 !== 'undefined') {

// If a web3 instance is already provided by Meta Mask.

App.web3Provider = web3.currentProvider;

web3 = new Web3(web3.currentProvider);

} else {

// Specify default instance if no web3 instance provided

App.web3Provider = new
Web3.providers.HttpProvider('http://localhost:7545');

web3 = new Web3(App.web3Provider);

49 | P a g e
return App.initContract();

},

initContract: function() {

$.getJSON("Election.json", function(election) {

// Instantiate a new truffle contract from the artifact

App.contracts.Election = TruffleContract(election);

// Connect provider to interact with contract

App.contracts.Election.setProvider(App.web3Provider);

return App.render();

});

},

render: function() {

var electionInstance;

var loader = $("#loader");

var content = $("#content");

// Load account data

web3.eth.getCoinbase(function(err, account) {

if (err === null) {

50 | P a g e
if (account == null){

loader.show();

content.hide();}

else{

App.account = account;

$("#accountAddress").html("Your Account: " + account);

}}

});

App.contracts.Election.deployed().then(function(instance){

electionInstance = instance;

return electionInstance.electionStarted().then(function(started){

if(started){

$("#addCandidatesDiv").hide();

$("#StartTiming").hide();

loader.hide();

content.show();

}).catch(function(error) {

console.warn(error);

51 | P a g e
});

})

// Load contract data

App.contracts.Election.deployed().then(function(instance) {

electionInstance = instance;

return electionInstance.candidatesCount();

}).then(function(candidatesCount) {

var candidatesResults = $("#candidatesResults");

candidatesResults.empty();

var candidatesSelect = $("#candidatesSelect");

candidatesSelect.empty();

for (var i = 1; i <= candidatesCount; i++) {

electionInstance.candidates(i).then(function(candidate) {

var id = candidate[0];

var name = web3.toAscii(candidate[1]);

var voteCount = candidate[2];

// Render candidate ballot option

var candidatesOption = "<option value='" + id + "' >" + name + "</ option>";

candidatesSelect.append(candidatesOption);

52 | P a g e
var candidateTemp = "<tr><th>" + id + "</th><td>" + name + "</td><td>" +
voteCount+"</td></tr>";

candidatesResults.append(candidateTemp);

});

return electionInstance.voters(App.account);

}).then(function(hasVoted) {

// Do not allow a user to vote

if(hasVoted) {

$('#voteCandidateForm').hide();

loader.hide();

content.show();

}).catch(function(error) {

console.warn(error);

});

},

castVote: function() {

var candidateId = $('#candidatesSelect').val();

App.contracts.Election.deployed().then(function(instance) {

return instance.vote(candidateId, { from: App.account });

}).then(function(result) {

53 | P a g e
// Wait for votes to update

}).catch(function(err) {

console.error(err);

});

},

addCandidates: function() {

var candidateName = $('#candidateName').val();

App.contracts.Election.deployed().then(function(instance){

return instance.addCandidate(candidateName, { from: App.account });

}).then(function(result) {

// Wait for votes to update

}).catch(function(err) {

console.error(err);

});

},

startVoting: function () {

App.contracts.Election.deployed().then(function(instance) {

return instance.startVote({from: App.account});

}).then(function(result){

54 | P a g e
}).catch(function(err){

console.error(err);

});

},

setTimer: function(){

var hour = $('#end_hours').val();

var mins = $('#end_minutes').val();

h = parseInt(hour);

m = parseInt(mins);

App.contracts.Election.deployed().then(function(i){

return i.setTimer(h,m, {from: App.account});

}).then(function(result){

}).catch(function(err){

console.error(err);

});

},

getTimer: function(){

App.contracts.Election.deployed().then(function(i){

return i.getTimer({from: App.account});

55 | P a g e
}).then(function(result){

console.log((result));

}).catch(function(err){

console.error(err);

});

},

getWinner: function(){

App.contracts.Election.deployed().then(function(instance) {

electionInstance = instance;

return electionInstance.candidatesCount();

}).then(function(candidatesCount) {

var max = [0,"",0];

var candidatesResults = $("#winnerName");

candidatesResults.empty();

for (var i = 1; i <= candidatesCount; i++) {

electionInstance.candidates(i).then(function(candidate) {

if(max[2]<candidate[2]){

max[0] = candidate[0];

max[1] = web3.toAscii(candidate[1]);

56 | P a g e
max[2] = candidate[2];

var candidateTemp = "<br/>"+"Id: " + max[0]+"<br/>"+"Name: "+ max[1] +


"<br/>No. of votes:" + max[2]+"<br/>";

candidatesResults.append(candidateTemp);

});

})

};

$(function() {

$(window).load(function() {

App.init();

});

});

57 | P a g e
Candidate id:-

var Election = artifacts.require("./Election.sol");

var electionInstance;

contract("Election",function(accounts){

it("initializes with two candidates",function(){

return Election.deployed().then(function(instance){

return instance.candidatesCount();

}).then(function(count){

assert.equal(count,2);

});

});

it("it initializes the candidates with correct value",function(){

return Election.deployed().then(function(instance){

electionInstance = instance;

return electionInstance.candidates(1);

}).then(function(candidate){

assert.equal(candidate[0],1,"correct cand1 id");

assert.equal(candidate[1],"Candidate 1","correct cand1 id");

assert.equal(candidate[2],0,"correct cand1 id");

return electionInstance.candidates(2);

}).then(function(candidate){

58 | P a g e
assert.equal(candidate[0],2,"correct cand2 id");

assert.equal(candidate[1],"Candidate 2","correct cand2 id");

assert.equal(candidate[2],0,"correct cand2 id");

});

});

})

59 | P a g e
RESULTS
TABLES :-
Table Name :- VOTING USING BLOCKCHAIN

Column Data Type

Admin_id Integer

Admin_name Varchar

Admin_address Integer

Table Name :- Election Candidate

Column Data Type


Candidate_id Integer
Candidate_name Varchar

Table Name :- voter

Column Data Type


voters_id Integer

60 | P a g e
SCREENSHOTS:-

61
62
63
REFRENCE AND BIBLIOGRAPHY

1) www.stackoverflow.com

2) www.github.com

3) www.youtube.com

4) Rifa Hanifatunnisa, Budi Rahardjo ”Blockchain Based EVoting Recording System


Design” School of Electrical Engineering and Informatics .

64

You might also like