It is the simplest implementation of Smart Contract to get a quick hands-on with the intricacies of ethereum development.
- Build and interact with a smart contract
- Test the smart contract
- Visualise everything using Ganache
This repo is dedicated to all the members of Facebook Developer Circles, Delhi.
- Install truffle
$> npm install -g truffle
- Download ganache from (https://truffleframework.com/ganache)
- Run
Ganache
- Clone this repo
$> git clone https://github.com/shubhamoy/HelloEthereum
$> truffle migrate --network ganache
- After completion of the above command, switch to
Ganache
and it should show the contract creation and contract calls.
- Open Truffle Console and connect it to
Ganache
$> truffle console --network ganache
- Create instance of the smart contract
truffle(ganache)> Election.deployed().then((instance) => { app=instance })
- Get the vote count
truffle(ganache)> app.count.call().then(count => count.toNumber())
- Call the upvote method
truffle(ganache)> app.upvote({from: web3.eth.accounts[1]})
- Call the upvote method
truffle(ganache)> app.upvote({from: web3.eth.accounts[2]})
- Finally, check the vote count value
truffle(ganache)> app.count.call().then(count => count.toNumber())
- Test Cases
./test/Election_Test.js
- Test the contract
$>truffle test --network ganache
- If you are unable to connect to Ganache, then after running Ganache check for the host and port.
In case, it isn't running on
http://localhost:7545
then update thetruffle.js
file with the new host and port details. - For any other problem, please raise an issue.
me[at]shubhamoy[dot]com