Skip to content

Commit 6683a4e

Browse files
committed
initial commit
0 parents  commit 6683a4e

File tree

6,104 files changed

+1056998
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,104 files changed

+1056998
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 0
6+
}

README.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Build your First Decentralized Application (DApp) Tutorial
2+
3+
A quick tutorial to get your first DApp up and running without any frameworks!
4+
5+
By Ben Stewart <br/>
6+
Last Updated:2/18/2018 <br/>
7+
8+
Install Dependencies:
9+
1. ganache-cli ```npm install ganache-cli [email protected]```
10+
2. solc ```npm install solc```
11+
12+
Directions:
13+
1. Git Clone this repository
14+
2. Run ganache-cli ```node_modules/.bin/ganace-cli```
15+
3. Open up Nodejs console ```node```
16+
4. Compile the contract
17+
* ```code = fs.readFileSync('Voting.sol').toString()```
18+
* ```solc = require('solc')```
19+
* ```compiledCode = solc.compile(code)```
20+
5. Deploy the contract
21+
* ```abiDefinition = JSON.parse(compiledCode.contracts[':Voting'].interface)```
22+
* ```VotingContract = web3.eth.contract(abiDefinition)```
23+
* ```byteCode = compiledCode.contracts[':Voting'].bytecode```
24+
* ```deployedContract = VotingContract.new(['Rama','Nick','Jose'],{data: byteCode, from: web3.eth.accounts[0], gas: 4700000})```
25+
* ```deployedContract.address```
26+
* ```contractInstance = VotingContract.at(deployedContract.address)```
27+
28+
Interacting with contract through nodejs console
29+
```
30+
> contractInstance.totalVotesFor.call('Rama')
31+
Output: { [String: '0'] s: 1, e: 0, c: [ 0 ] }
32+
33+
> contractInstance.voteForCandidate('Rama', {from: web3.eth.accounts[0]})
34+
Output: '0xdedc7ae544c3dde74ab5a0b07422c5a51b5240603d31074f5b75c0ebc786bf53'
35+
36+
> contractInstance.voteForCandidate('Rama', {from: web3.eth.accounts[0]})
37+
Output: '0x02c054d238038d68b65d55770fabfca592a5cf6590229ab91bbe7cd72da46de9'
38+
39+
> contractInstance.voteForCandidate('Rama', {from: web3.eth.accounts[0]})
40+
Output: '0x3da069a09577514f2baaa11bc3015a16edf26aad28dffbcd126bde2e71f2b76f'
41+
42+
> contractInstance.totalVotesFor.call('Rama').toLocaleString()
43+
Output: '3'
44+
```
45+
46+
Interacting with contract via front GUI
47+
1. Update the contract instance address in index.js
48+
* Can run command ```contractInstance.address``` to find address
49+
2. Open index.html in your browser
50+
# voting-blockchain-dapp

index.html

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Hello World</title>
5+
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
6+
<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' rel='stylesheet' type='text/css'>
7+
</head>
8+
<body class="container">
9+
<h1>A Simple Blockchain Voting Application</h1>
10+
<div class="table-responsive">
11+
<table class="table table-bordered">
12+
<thead>
13+
<tr>
14+
<th>Candidate</th>
15+
<th>Votes</th>
16+
</tr>
17+
</thead>
18+
<tbody>
19+
<tr>
20+
<td>Bill</td>
21+
<td id="candidate-1"></td>
22+
</tr>
23+
<tr>
24+
<td>Bob</td>
25+
<td id="candidate-2"></td>
26+
</tr>
27+
</tbody>
28+
</table>
29+
</div>
30+
<input type="text" id="candidate" />
31+
<a href="#" onclick="votesForTeam()" class="btn btn-primary">Votes</a>
32+
</body>
33+
<script src="https://cdn.rawgit.com/ethereum/web3.js/develop/dist/web3.js"></script>
34+
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
35+
<script src="./index.js"></script>

index.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
3+
abi = JSON.parse('[{"constant":false,"inputs":[{"name":"candidate","type":"bytes32"}],"name":"totalVotesFor","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"candidate","type":"bytes32"}],"name":"validCandidate","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"votesReceived","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"x","type":"bytes32"}],"name":"bytes32ToString","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"candidateList","outputs":[{"name":"","type":"bytes32"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"candidate","type":"bytes32"}],"name":"voteForCandidate","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"contractOwner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"inputs":[{"name":"candidateNames","type":"bytes32[]"}],"payable":false,"type":"constructor"}]')
4+
VotingContract = web3.eth.contract(abi);
5+
// In your nodejs console, execute contractInstance.address to get the address at which the contract is deployed and change the line below to use your deployed address
6+
contractInstance = ScoringContract.at('0x8673fb2ae00895efd903c489b18231b1365b8b39');
7+
teams = {"Los Angeles Lakers": "team-1", "New York Knicks": "team-2"}
8+
9+
function pointForTeam() {
10+
candidateName = $("#team").val();
11+
contractInstance.pointForTeam(teamName, {from: web3.eth.accounts[0]}, function() {
12+
let div_id = teams[teamName];
13+
$("#" + div_id).html(contractInstance.totalPointsFor.call(teamName).toString());
14+
});
15+
}
16+
17+
$(document).ready(function() {
18+
teamNames = Object.keys(team);
19+
for (var i = 0; i < teamNames.length; i++) {
20+
let name = teamNames[i];
21+
let val = contractInstance.totalPointsFor.call(name).toString()
22+
$("#" + teams[name]).html(val);
23+
}
24+
});

node_modules/.bin/acorn

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/errno

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/ganache-cli

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/json5

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/miller-rabin

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/mkdirp

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/rimraf

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/semver

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/sha.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/solcjs

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/uglifyjs

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/webpack

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/which

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/acorn-dynamic-import/CHANGELOG.md

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/acorn-dynamic-import/LICENSE

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/acorn-dynamic-import/README.md

+33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/acorn-dynamic-import/lib/index.js

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/acorn-dynamic-import/lib/inject.js

+70
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/acorn-dynamic-import/node_modules/.bin/acorn

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/acorn-dynamic-import/node_modules/acorn/.npmignore

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)