Giter Site home page Giter Site logo

ethereum-voting-api's Introduction

ethereum-voting-api

An api for a voting app built on ethereum.

Getting Started

These instructions will get you a copy of the project up and running on your local machine

Prerequisites

  • Nodejs - The web framework used
  • Ganache - Simulates an ethereum network for local development
  • Truffle - development environment for ethereum. Can be installed with $ npm install -g truffle

Installing

A step by step series of examples that tell you how to get a development env running

Clone this repo

$ git clone [email protected]:ShemManyu/ethereum-voting-api.git

Install dependencies

$ npm install

Change into truffle/ directory

$ cd truffle

Make sure ganache is running get the port it is running on in localhost and make sure is same as the one in truffle.js file. Compile contracts and deploy to the ganache network.

$ truffle compile
$ truffle deploy --reset --network ganache
Running migration: 2_vote.js
  Replacing vote...
  ... 0x301d03eafc4f6bc13b26ca5771a6b6e783f47f710b2ed5bbad8288d7a2646a6e
  vote: 0x4610b7b59920b760d1164406a6f13f09043b6af3
Saving artifacts...

Get the vote contract string in this case 0x4610b7b59920b760d1164406a6f13f09043b6af3 and replace the contract variable in the index.js file (line 8) this string will change evrytime you do a truffle deploy.

Go one directory up and run the index.js file to get node running

$ node index.js

If no errors show up you can do GET and POST requests to cast and retrieve votes. There are only two candidates

GET Vote count for candidate 1

$ curl -X GET http://localhost:8080/count/1

"0"

To cast vote you'll need the address of an account on the ganche network. To vote for candidate 1

$ curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "candidate=1&account=0x25660625C2919b6998c5dD7300ACE7a03db89855" http://localhost:8080/vote 

Running get again you can see the count was incremented

$ curl -X GET http://localhost:8080/count/1

"1"

Once the address of an account has been used to vote it cannot be used again. When we try to vote for candidate 2 with the same account

$ curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "candidate=2&account=0x25660625C2919b6998c5dD7300ACE7a03db89855" http://localhost:8080/vote 

"Account has already voted"

ethereum-voting-api's People

Contributors

shemmanyu avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.