Skip to content

VoteAppBlockchain/voting-app-backend

Repository files navigation

voting-app-backend

This repo contains the voting application's backend source code. The backend was written in Node.Js. To see mobile code, you can look here.

Run

Firstly, you need to install some packages. To install all packages, you can run the following command.

$ npm install

To store the voter's information in database, you need to create a new database in PostgreSQL which named as voting_app_db. When you run the server, the table and columns are created.

Also, you should install ganache-cli to your environment. You can type the following command.

$ npm install -g ganache-cli

After installing packages, you can start the server with the following command. Firstly, you need to run ganache-cli to create avaliable accounts. Then, you can start server.

$ ganache-cli

Important point is that you need to run those commands in different terminals.

$ npm run start

You need to see contract address. If you see address, server is running successfully.

Updating and Re-compiling Smart Contract

If you change the implementation of the smart contract, you need to compile the Voting.sol file. To compile the smart contract, you need to install solc package.

$ npm install solc

After you installed the package, you can compile the Solidity file with the following command.

$ solcjs --bin --abi Voting.sol

Endpoints

Vote

Endpoint: POST http://localhost:8082/vote
JSON Body: 
{
    "candidate": 1,
    "from": "0xB03e6539b5f8D523772925bE5C2eF1e6106c3540"
}

You need to give voter account address into from in JSON.

Get Election Results

Endpoint: POST http://localhost:8082/get/election-results
JSON Body:
{
  "from": "0x2537b143CFC60A8D3ccfC9e6D924C08Baa357899"
}

It returns the JSON object which includes the candidates and vote counts for each of them.

Check My Vote

Endpoint: POST http://localhost:8082/get/check-my-vote
JSON Body:
{
"from": "0x76936384eabE3d811dEFf2af5f63c0A5F116ceDC"
}

It checks the vote which is casted by the voter and returns the result to client.

Get Candidate List

Endpoint: GET http://localhost:8082/candidates

It returns the list of candidate list with hex values

Login

Endpoint: POST http://localhost:8082/login
{
"id_number": "12345678902",
"password": "12345678"
}

Checks the identity number and password and verifies the voter.

Tech Stack

Team Members