1NIP-882======34Polls5-----67`draft` `optional`89This NIP defines the event scheme that describe Polls on nostr.1011## Events1213### Poll Event1415The poll event is defined as a `kind:1068` event.1617- **content** key holds the label for the poll.1819Major tags in the poll event are:2021- **option**: The option tags contain an OptionId(any alphanumeric) field, followed by an option label field.22- **relay**: One or multiple tags that the poll is expecting respondents to respond on.23- **polltype**: can be "singlechoice" or "multiplechoice". Polls that do not have a polltype should be considered a "singlechoice" poll.24- **endsAt**: signifying at which unix timestamp the poll is meant to end.2526Example Event2728```json29{30 "content": "Pineapple on pizza",31 "created_at": 1719888496,32 "id": "9d1b6b9562e66f2ecf35eb0a3c2decc736c47fddb13d6fb8f87185a153ea3634",33 "kind": 1068,34 "pubkey": "dee45a23c4f1d93f3a2043650c5081e4ac14a778e0acbef03de3768e4f81ac7b",35 "sig": "7fa93bf3c430eaef784b0dacc217d3cd5eff1c520e7ef5d961381bc0f014dde6286618048d924808e54d1be03f2f2c2f0f8b5c9c2082a4480caf45a565ca9797",36 "tags": [37 ["option", "qj518h583", "Yay"],38 ["option", "gga6cdnqj", "Nay"],39 ["relay", "<relay url1>"],40 ["relay", "<relay url2>"],41 ["polltype", "singlechoice"],42 ["endsAt", "<unix timestamp in seconds>"]43 ]44}45```4647### Responses4849The response event is a `kind:1018` event. It contains an e tag with the poll event it is referencing, followed by one or more response tags.5051- **response** : The tag contains "response" as its first positional argument followed by the option Id selected.5253The responses are meant to be published to the relays specified in the poll event.5455Example Response Event5657```json58{59 "content": "",60 "created_at": 1720097117,61 "id": "60a005e32e9596c3f544a841a9bc4e46d3020ca3650d6a739c95c1568e33f6d8",62 "kind": 1018,63 "pubkey": "1bc70a0148b3f316da33fe7e89f23e3e71ac4ff998027ec712b905cd24f6a411",64 "sig": "30071a633c65db8f3a075c7a8de757fbd8ce65e3607f4ba287fe6d7fbf839a380f94ff4e826fbba593f6faaa13683b7ea9114ade140720ecf4927010ebf3e44f",65 "tags": [66 ["e", "1fc80cf813f1af33d5a435862b7ef7fb96b47e68a48f1abcadf8081f5a545550"],67 ["response", "gga6cdnqj"],68 ["response", "m3agjsdq1"]69 ]70}71```7273### Poll Types7475The polltype setting dictates how multiple response tags are handled in the `kind:1018` event.7677- **polltype: singlechoice**: The first response tag is to be considered the actual response.78- **polltype: multiplechoice**: The first response tag pointing to each id is considered the actual response, without considering the order of the response tags.7980### Counting Results8182Results can be queried by fetching `kind:1018` events from the relays specified in the poll.83The results displayed should only be 1 vote event per pubkey.84In case of multiple events for a pubkey, the event with the largest timestamp within the poll limits should be considered.8586Example for querying polls.8788```ts89const fetchVoteEvents = (filterPubkeys: string[]) => {90 let resultFilter: Filter = {91 "#e": [pollEvent.id],92 kinds: [1018],93 };94 if (filterPubkeys?.length) {95 resultFilter.authors = filterPubkeys;96 }97 if (pollExpiration) {98 resultFilter.until = Number(pollExpiration);99 }100 pool.subscribeMany(relays, [resultFilter], {101 onevent: handleResultEvent,102 });103};104```105106Example for maintaining OneVotePerPubkey107108```ts109const oneVotePerPubkey = (events: Event[]) => {110 const eventMap = new Map<string, Event>();111112 events.forEach((event) => {113 if (114 !eventMap.has(event.pubkey) ||115 event.created_at > eventMap.get(event.pubkey)!.created_at116 ) {117 eventMap.set(event.pubkey, event);118 }119 });120121 return Array.from(eventMap.values());122};123```124125### Relays126127It is advisable for poll authors to use relays that do not allow backdated events and do not honor kind:5 (delete) requests for vote events in order to maintain the integrity of poll results after the poll has ended.128129### Curation130131The clients may configure fetching results by specific people. This can be achieved by creating `kind:30000` follow sets, and fetching results only from the follow set.132Clients can also employ other curation algorithms, like Proof Of Work and Web of Trust scores for result curations.