I am trying to assemble a list of all voters on a referendum
with their votes, etc. I need help on what storage
pallet to call, I tried calling the functions on the convictionVoting
pallet which is not working for me.
1 Answer
Here are some snippets that may help you get started:
const votes = await api.query.convictionVoting.votingFor.entries();
votes.forEach((vote) => {
if (vote[1].toHuman()['Casting']) {
if (vote[1].toHuman()['Casting']['votes'].length > 0) {
console.log(vote[0].toHuman());
console.log(JSON.stringify(vote[1].toHuman(), null, 4));
}
}
});
const referenda = await api.query.referenda.referendumInfoFor.entries();
referenda.forEach(async (referendum) => {
if (referendum[1].toHuman()['Ongoing']) {
const referendumIndex = referendum[0].args[0].toNumber();
console.log("Referendum:", referendumIndex);
console.log(referendum[1].toJSON());
}
});
Resources