Skip to content

Election hosted on a local Ethereum blockchain network with Truffle, Ganache, Metamask, and NodeJS.

License

Notifications You must be signed in to change notification settings

Lexxeous/local_election

Repository files navigation

Lexxeous's Smart Contract Election:

Credit

The content contained in this repository is a result of following The Ultimate Ethereum Dapp Tutorial (How to Build a Full Stack Decentralized Application Step-By-Step). If you do not want to follow along with the article, you can find the original YouTube video, by Dapp University, here.

Summary

This application will be using a locally hosted Ethereum blockchain network with the help of Ganache and Truffle. This local network will be provided with fake accounts and fake Ether, on port 7545 by default. A simple smart contract called Election.sol is written with a constructor, a candidate model, voter and candidate mappings, & add_candidate() and vote() functions.

There is also a file ./test/election.js that takes advantage of the Mocha testing framework and the Chai assertion library to ensure proper functionality of the smart contract before deployment. The file can be ran with $ truffle test.

Migrations are written to deploy the application/smart contract to the local blockchain, while Ganache is running. Deployment can be done by running truffle migrate --reset.

After installing the Metamask extension and creating an account, one of the fake accounts from Ganache can be imported into Metamask by providing the private key. Instead of trying to run the application on the main Ethereum network (Mainnet), a custom network/RPC can be added to Metamask by providing a custom name, the network URL (http://127.0.0.1:7545), and the chain ID (1337 for me).

After migrating/deploying the smart contract to the local blockchain, the HTMl, CSS, & JS sources can be deployed in development mode by running npm run dev. This will host the NodeJS web application on http://localhost:3000 by default.

Prerequisites

Run npm install to get all of the necessary NodeJS packages.

Releases

No releases published

Packages

No packages published

Languages