dappconnect-voting-sdk/packages/core/README.md

50 lines
1.5 KiB
Markdown
Raw Normal View History

2021-08-09 12:53:39 +00:00
# Gassless voting over waku
2021-08-09 08:50:10 +00:00
2021-08-09 12:53:39 +00:00
## Waku Voting
2021-08-09 09:57:02 +00:00
Objects of type of WakuVoting, hold their own Waku objects and also store list of polls and votes for later use.
Creating instance of WakuVoting:
2021-08-09 12:53:39 +00:00
WakuVoting constructor expects name of DApp and address of a token, also as optional parameter can take custom Waku object.
2021-08-09 09:57:02 +00:00
```ts
import WakuVoting from 'core'
2021-08-09 12:53:39 +00:00
const wakuVoting = new WakuVoting('myDapp', '0x00000000000')
2021-08-09 09:57:02 +00:00
```
objects of type WakuVoting expose functions:
createTimedPoll(signer: JsonRpcSigner, question:string, answers: string[], pollType: enum, minToken?: BigNumber, endTime?: number)
getTimedPolls()
sendTimedPollVote(signer: JsonRpcSigner, pollHash: string, selectedAnswer:number, sntAmount?: number)
2021-08-09 12:53:39 +00:00
## Polls
2021-08-09 08:50:10 +00:00
2021-08-09 12:53:39 +00:00
### Creating time-limited poll
2021-08-09 08:50:10 +00:00
To create a poll user has to send a message over waku network on specific topic
2021-08-09 09:57:02 +00:00
`/{dapp name}/waku-polling/timed-polls-init/proto`
2021-08-09 08:50:10 +00:00
For a poll to be started waku message has to have specific fields:
```proto
message PollInit {
bytes owner = 1; // Address of a poll owner/initializer
int64 timestamp = 2; // Timestamp of a waku message
string question = 3;// Question of a poll
2021-08-09 12:53:39 +00:00
repeated string answers = 4; // Possible answers to poll
2021-08-09 08:50:10 +00:00
enum PollType {
WEIGHTED = 0;
NON_WEIGHTED = 1;
}
PollType pollType = 5 // type of poll
optional bytes minToken = 6 // amount of token needed for NON_WEIGHTED poll to be able to vote
int64 endTime = 7 // UNIX timestamp of poll end
bytes signature = 8 // signature of all above fields
}
2021-08-09 09:57:02 +00:00
```