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.
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.
Run
npm install
to get all of the necessary NodeJS packages.