This package provide an easy to use API for interacting with the Vote Contract in a blockchain.
- Testrpc for local development blockchain
npm install
You need to have Testrpc installed and running. Execute in a separate terminal:
npm install -g ethereumjs-testrpc
testrpc
Update test.js
to match the wallet address and private key returned by Testrpc.
To test, execute:
npm test
The file contract.json
is the interface of the voting contract. See Vote-On-Ethereum/Contract how to make it.
See use-example.js
Initialize the object.
Encode as one JSON:
providerURL
[URL] Synced RPC-enabled node URLwallet
[JSON]public
[address] Address use to sign the transaction. Should be the same as in the signerURL or signer function
signerURL
[URL] The URL of the online signersigner
[function] Local signer function to sign transaction locally
Only one of signerURL
and signer
is required. signer
is available for test purpose.
Load a contract already deployed
address
[address] The address of the deployed contract
Create a new vote
question
[string] The question for the new vote
Add a proposal to the vote
proposal
[string] The proposal to add
Vote for a proposal
voterHash
[bytes64] The sha256 encoded hex identification string of the voter Ex: 0xa18aaa6c6b929b866051b69a785a6cdce5bdd564d41be247c7d5ef7c2e2e2271proposal
[integer] The id of the proposal
The promise will resolve when the vote is verify and on the blockchain. It may take time.
The vote question
The number of total vote
The number of proposals
Get all proposals data
- [array] Proposal array
name
[string] The name of the proposal
Get a specific proposal data
index
[integer] The index of the proposal
name
[string] The name of the proposal
Get the number of vote for a specific proposal
index
[integer] The index of the proposal
Get the number of vote per proposal
- [array] Proposal array
- [integer] The number of vote for this proposal
Get the number of votersHash array
Get the hash of a voter by its index
index
[integer] The index of the voter
Get the data of a voter
voterHash
[bytes64] The index of the voter
voterHash
[bytes64] The hash of the votervoted
[boolean] True if the voter has votedproposalVoted
[integer] The index of the voted proposalvotersHashIndex
[integer] The index of voter in the votersHash array
Get the data of all voters
- [array] Voter array
voterHash
[bytes64] The hash of the votervoted
[boolean] True if the voter has votedproposalVoted
[integer] The index of the voted proposalvotersHashIndex
[integer] The index of voter in the votersHash array