Skip to content

This is a voting application based on Ethereum platform.

Notifications You must be signed in to change notification settings

guangningyu/voting-ethereum-dapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This is a voting application based on Ethereum platform.
Source: Full Stack Hello World Voting Ethereum Dapp Tutorial

Installation

npm install ethereumjs-testrpc --save
npm install web3@0.20.1 --save
npm install solc --save

How To Run

Start testrpc:

node_modules/.bin/testprc

Initialize a web3 object in the node console:

> Web3 = require('web3');
> web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
> web3.eth.accounts

Compile the contract:

> code = fs.readFileSync('voting.sol').toString()
> solc = require('solc')
> compiledCode = solc.compile(code)

Use VotingContract.new to deploy the contract:

> abiDefinition = JSON.parse(compiledCode.contracts[':Voting'].interface)
> VotingContract = web3.eth.contract(abiDefinition)
> byteCode = compiledCode.contracts[':Voting'].bytecode
> deployedContract = VotingContract.new(['Rama', 'Nick', 'Jose'], {data: byteCode, from: web3.eth.accounts[0], gas: 4700000})
> deployedContract.address
> contractInstance = VotingContract.at(deployedContract.address)

Interact with the contract:

> contractInstance.totalVotesFor.call('Rama')
> contractInstance.voteForCandidate('Rama', {from: web3.eth.accounts[0]})
> contractInstance.voteForCandidate('Rama', {from: web3.eth.accounts[0]})
> contractInstance.voteForCandidate('Rama', {from: web3.eth.accounts[0]})
> contractInstance.totalVotesFor.call('Rama')

About

This is a voting application based on Ethereum platform.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published