This is our BE Project based on Blockchains where we are building e-Voting Dapp using Truffle Framework.
- Anish Pawar
- Prasad Pathak
- Pabitra Parida
- Riya Nagpal
To design a next generation secure, transparent, tamper proof voting system built on the foundations of the blockchain.
In order to build and run our project we need a few dependencies :
The first dependency is NPM which comes with Node.js. You can check if you have NPM by typing the following in your terminal:
$ node -v
You can download Node.js here
Next dependency is Truffle Framework which allows us to build decentralized applications on Ethereum blockchain. It also provides us with tools which allow us to deploy smart contracts using Solidity language. It aslo helps us develop client side applications.
You can install Truffle by running the following command in your terminal :
$ npm install -g truffle
Ganache is a local in-memory blockchain. It helps us simulate an Ethereum blockchain with 10 accounts which are preloaded 100 fake ether each.
You can download Truffle Framework by clicking here
The next dependency is Metamask which is a Google Chrome extension. Since blockchain is a network in itself we need a special browser to connect to it. We'll be able to connect to our local blockchain using our own local account with the help of Metamask.
You can download Metamask by clicking here
You will need to install Google Chrome if you dont have it. After installing make sure it is enabled in your list of extensions. You'll see a a fox icon in the top right corner of your screen.
Basic editor to view and modify code. I'll recommend using Sublime Text because it has plugins for syntax highliting for Solidity language.
You can install the free version by clicking here
Optional but highly recommended to easily read and write Solidity code, which may not be highlighted properly on some editors.
You can install "Ethereum Package" that provides syntax highlighting for Solidity.
git clone https://github.com/anish2197/Voting-dApp
Install NPM, Truffle, Ganache and Metamask.
Open the Ganache GUI client. This will start the local in-memory blockchain instance. Note the RPC server address, we will need it later to connect to the blockchain.
Open the bash terminal in your project folder. Run the following command :
$ truffle.cmd migrate --reset
This will deploy our contract Election.sol. Since the contents of blockchain cannot be altered, we need to reset the contract every time we restart Ganache.
Open another bash terminal in your project folder. This will be used to start the server. Run the following command :$ npm run dev
This should automatically open a window in your browser with the client-side application.
- Register a free account using the Metamask GUI and login in your account.
- We'll use Metamask to log into the blockchain network. Click on "Main Ethereum Network" and select "Custom RPC Server". Paste the RPC server address from Step 3. and hit save. You are now on the blockchain network.
- Open Ganache GUI. We now need to log in to the blockchain using one of the 10 accounts provided by Metamask. Select any one of your choice and copy its private key using the key icon on the right side of the GUI.
- Open Metamask GUI. Click on the circular icon on the top right side of the GUI. Select on "Import Account". Paste the private key. You have now successfully logged in the blockchain with a valid account.
Visit this URL in your browser: http://localhost:3000.
You may need to restart your browser.
- Can read from blockchain and display the list of candidates.
- Keep a live track of the data of the candidates(i.e. vote count).
- Vote on behalf of an account.
- Set a timer for the elections.
- Announce the winner after the timer goes off.
- Voter registration, reject unregistered voters.
5 test cases have been designed to test the behaviour of the dapp.
Testing is done by writing a Javascript to simulate the client-side interaction. Mocha Testing Framework and Chai Assertion Library are used for this purpose, which come bundled with Truffle Framework.
You can find these Javascripts in the following path : ./Elections/test/election.js
Use the following command in the bash to run the Javascript for the tests :
$ truffle test
- Test to verify if the candidate count is correct.
- Fails if the candidate count is different than 2.
- Test to verify the candidate details.
- Fails if the candidate name, ID and vote count is not valid.
- Passing of these 2 tests indicates that the global variables have been correctly initialized by the constructor().
- Test to check the behaviour of the vote.
- Checks for two things:
- Vote has been registered into the blockchain
- Vote has only been incremented by 1
- Test to check if the chosen candidate ID on the vote is valid.
- Fails if the chosen ID is out of bounds.
- Test to check if the dapp allows double voting.
- Fails when we try to vote for the second time from an account and a proper exception is thrown.