codeamt / EthElection

A sample voting dapp powered by the Ethereum blockchain, the Truffle Framework and Metamask.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EthElection

This is a simple example decentralized app (dApp) to demonstrate voting via the Ethereum blockchain, powered by:

Demo on Ginache Network

This demo is hosted on Heroku and works if you (1) have a local Ginache network running on your system and (2) the Metamask extension for your browser installed. More details on installing dependencies below.

Running Repo Locally

To run the app in your own development environment, do the following

1. Install Homebrew:

In the terminal:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew doctor
brew prune
brew -v

2. Install Node, NPM, Weback and Truffle

Now, install build essentials (if you don't have these already:

brew install node               #installs both node and npm
npm install -g truffle
npm install -g webpack          #for the cli
node -v
npm -v
truffle -v 
webpack -v

3. Clone this repo

Then, clone a copy of this repo:

git clone https://github.com/codeamt/EthElection.git

4. Download/Install Truffle's Ginache

Ginache sets up a local rpc server and blockchain for testing purposes. It also comes with 5 Ethereum test accounts, preloaded with ether.

Download here: Ginache Download for Mac OS

Once downloaded and launched, your dashboard should look like this:


5. Install/Setup Metamask

Metamask has a few extensions available, depending upon your preferred browser (Chrome, Firefox, or Opera), but also offers their own web3 browser Brave.

To get the right extension, download here.

Once you've completed the Metamask onboarding process, switch the network from the MainNet to your local rpc.

Steps:

  • In Ginache, copy the RPC server url up at the top (which should be http://127.0.0.1:7545)
  • Go back to the Metamask extension, click on the drop down menu where it says MainNet and select the "Custom RPC" option:


- Then paste the Ginache RPC url where it says "New RPC url" and save:


Metamask will automagically import your first eth address listed in Ginache.

6. Build the Project and Vote!

In the terminal:

cd electionDemo && npm run dev

Now go to http://localhost:7545 in the browser, and the dapp should be running! You're allowed one vote per address!

7. Import Addresses to Test Vote Incrementing

If you want to see the Result board increment more than once, you'll have to import more eth addresses from Ginache into Metamask. To achieve this:

Steps:

  • In Ginache, under accounts, click on the key icon by one of the other accounts you'd like to sync with Metamask to copy it's private key.
  • Back in Metamask, click on the user profile icon and select "import address"


  • Paste the private key you copied into the input:


After you switch to that account, you can cast another vote and see the vote count for your candidate go up again!

Future Updates

In coming weeks, I'll be updating the smart contracts in order to save end users from having to spend money (albeit, fake) to vote. Stay tuned!

About

A sample voting dapp powered by the Ethereum blockchain, the Truffle Framework and Metamask.


Languages

Language:JavaScript 97.0%Language:HTML 2.7%Language:CSS 0.2%