-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuse-example.js
More file actions
60 lines (53 loc) · 1.34 KB
/
use-example.js
File metadata and controls
60 lines (53 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
let Vote = require('vote-api')
let shajs = require('sha.js')
let vote = new Vote({
providerURL: "http://localhost:8545", //Synced RPC-enabled node URL
wallet: {
"public": "0x0E1A.........Dc" //Address use to sign the transaction. Should be the same as in the signerURL or signer function
},
signerURL: 'https://URL_TO_THE_ONLINE_SIGNER',
signer: rawTx => { //Signer function to sign transaction locally
rawTx.from = "0x0E1A.........Dc"
rawTx.gas = 3000000
return Promise.resolve(ethSigner.sign(rawTx, '0xd7bd......cc27c')) //Private key
}
})
//create new poll
console.log("create new poll");
vote.create("Who is the best?")
.then(_ => {
console.log("contract created", vote.instance.address)
})
//Add proposal
.then(_ => {
console.log("will add proposal")
})
.then(_ => {
return vote.addProposal("Nicolas")
})
.then(_ => {
return vote.addProposal("Thomas")
})
.then(_ => {
return vote.addProposal("Anthony")
})
.then(_ => {
return vote.addProposal("Manu")
})
//Vote
.then(_ => {
let voterName = "nicolas"
let voterHash = "0x" + shajs('sha256').update(voterName, 'utf8').digest('hex')
return vote.vote(voterHash, proposal)
})
//get number of vote
.then(_ => {
return vote.numberOfVote
})
.then(numberOfVote => {
console.log(numberOfVote + " total votes");
})
.catch(error => {
console.log(error)
})