Install these prerequisites to follow along with the tutorial. See free video tutorial or a full explanation of each prerequisite.
- NPM: https://nodejs.org
- Truffle: https://github.com/trufflesuite/truffle
- Ganache: http://truffleframework.com/ganache/
- Metamask: https://metamask.io/
git clone https://github.com/ArchLinuxStudio/election
$ cd election
$ npm install
Open the Ganache GUI client that you downloaded and installed. This will start your local blockchain instance. See free video tutorial for full explanation.
$ truffle migrate --reset
You must migrate the election smart contract each time your restart ganache.
See free video tutorial for full explanation of these steps:
- Unlock Metamask
- Connect metamask to your local Etherum blockchain provided by Ganache.
- Import an account provided by ganache.
$ npm run dev
Visit this URL in your browser: http://localhost:3000
If you get stuck, please reference the free video tutorial.
- Use
web3.eth.getAccounts()
to get accounts now - To bootstrap sample truffle project, use command
truffle unbox pet-shop
- Run geth node
geth --rinkeby --http --http.api personal,eth,net,web3 --allow-insecure-unlock
This can take dozens of hours, depending on your machine configuration and internet speed.
This will cost you close to 100GB or so of hard drive space.
- Create a new account
geth --rinkeby account new
- Attach into geth console
geth --rinkeby attach
And you can do many things in geth console
eth.syncing #check the syncing status
eth.accounts #check all accounts
eth.getBalance(eth.accounts[0]) #check account balance
personal.unlockAccount(eth.accounts[0],null,1200) #unlock a certain accont for 20 minutes
- Acquire eth from https://www.rinkeby.io/#faucet
Here they require that you have to post a twitter or facebook, which is disgusting.
- Migrate
truffle migrate --reset --compile-all --network rinkeby
- Verify deployment
geth --rinkeby attach
var contractAddress = "Your_Contract_Address"
var contractAbi = [Your_ABI_Array] #copy the abi array in build/contracts/Election.json, turn it into one line style
var electionContract = web3.eth.contract(contractAbi)
var electionInstance = electionContract.at(contractAddress)
electionInstance.candidates(1)
electionInstance.vote(1, {from: eth.accounts[0]});