Step 1 of 5
Ask the question
The poll's content is the question or label people will see.
NIP-88
DraftEvents
A poll is a kind 1068 event with a question and options; each vote is a kind 1018 event sent to the relays the poll names, and clients count one vote per person.
Edit the form or the JSON: both stay in sync, the badge says whether the result is valid, and tapping any field explains it.
How the parts connect: Ask and answer
Not signed yet · Demo keys only. These personas' secret keys are public on purpose.
Select any field in the form or the JSON to see what it does.
Step 1 of 5
The poll's content is the question or label people will see.
No course chapter covers this NIP yet. The editor above is the quickest way in.
Polls and votes are ordinary signed events.
Follow sets (kind 30000) can limit whose votes are counted.
Proof of work is one way to filter out spam votes.
Poll relays should ignore deletion requests for votes so results stay stable.
Specification text is quoted in English from the nostr-protocol/nips repository. Our explanations and the interface are translated. Source on GitHub at commit 0046368
This NIP defines the event scheme that describe Polls on nostr.
The poll event is defined as a kind:1068 event.
Major tags in the poll event are:
Example Event
{
"content": "Pineapple on pizza",
"created_at": 1719888496,
"id": "9d1b6b9562e66f2ecf35eb0a3c2decc736c47fddb13d6fb8f87185a153ea3634",
"kind": 1068,
"pubkey": "dee45a23c4f1d93f3a2043650c5081e4ac14a778e0acbef03de3768e4f81ac7b",
"sig": "7fa93bf3c430eaef784b0dacc217d3cd5eff1c520e7ef5d961381bc0f014dde6286618048d924808e54d1be03f2f2c2f0f8b5c9c2082a4480caf45a565ca9797",
"tags": [
["option", "qj518h583", "Yay"],
["option", "gga6cdnqj", "Nay"],
["relay", "<relay url1>"],
["relay", "<relay url2>"],
["polltype", "singlechoice"],
["endsAt", "<unix timestamp in seconds>"]
]
}
The 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.
The responses are meant to be published to the relays specified in the poll event.
Example Response Event
{
"content": "",
"created_at": 1720097117,
"id": "60a005e32e9596c3f544a841a9bc4e46d3020ca3650d6a739c95c1568e33f6d8",
"kind": 1018,
"pubkey": "1bc70a0148b3f316da33fe7e89f23e3e71ac4ff998027ec712b905cd24f6a411",
"sig": "30071a633c65db8f3a075c7a8de757fbd8ce65e3607f4ba287fe6d7fbf839a380f94ff4e826fbba593f6faaa13683b7ea9114ade140720ecf4927010ebf3e44f",
"tags": [
["e", "1fc80cf813f1af33d5a435862b7ef7fb96b47e68a48f1abcadf8081f5a545550"],
["response", "gga6cdnqj"],
["response", "m3agjsdq1"]
]
}
The polltype setting dictates how multiple response tags are handled in the kind:1018 event.
Results can be queried by fetching kind:1018 events from the relays specified in the poll.
The results displayed should only be 1 vote event per pubkey.
In case of multiple events for a pubkey, the event with the largest timestamp within the poll limits should be considered.
Example for querying polls.
const fetchVoteEvents = (filterPubkeys: string[]) => {
let resultFilter: Filter = {
"#e": [pollEvent.id],
kinds: [1018],
};
if (filterPubkeys?.length) {
resultFilter.authors = filterPubkeys;
}
if (pollExpiration) {
resultFilter.until = Number(pollExpiration);
}
pool.subscribeMany(relays, [resultFilter], {
onevent: handleResultEvent,
});
};
Example for maintaining OneVotePerPubkey
const oneVotePerPubkey = (events: Event[]) => {
const eventMap = new Map<string, Event>();
events.forEach((event) => {
if (
!eventMap.has(event.pubkey) ||
event.created_at > eventMap.get(event.pubkey)!.created_at
) {
eventMap.set(event.pubkey, event);
}
});
return Array.from(eventMap.values());
};
It 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.
The 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.
Clients can also employ other curation algorithms, like Proof Of Work and Web of Trust scores for result curations.