With PolkadotJS you can get information about a specific referendum with this code:
const referenda = await api.query.referenda.referendumInfoFor(48);
console.log(`Referenda: ${JSON.stringify(referenda.toHuman())}`);
And you get the total number of ayes and nayes votes, with other information:
Referenda: {"Ongoing":{"track":"0","origin":{"system":"Root"},"proposal":{"Lookup":{"hash_":"0x4bdd1d956c24c6dc9ce1c07f6c3cc1a82d5db63dc6d895bdd5a035f60ef58006","len":"106"}},"enactment":{"After":"100"},"submitted":"16,019,459","submissionDeposit":{"who":"DrQ3WAwSyMsZpaUvwP11j63QJC2wmGUH3BWPoxj5kqgA3A1","amount":"33,333,333,333"},"decisionDeposit":null,"deciding":null,"tally":{"ayes":"24,025,722,234,946,176","nays":"72,721,623,600,000,000","support":"17,151,464,474,841,370"},"inQueue":false,"alarm":["16,221,059",["16,221,059","0"]]}}
Is this one in Kusama
Also you can get the list of all referendums (Finished and OnGoing):
const allEntries = await api.query.democracy.referendumInfoOf.entries();
allEntries.forEach(([{ args: [id] }, referendum]) => {
console.log(`${id}: Referendum: ${JSON.stringify(referendum.toHuman())}`);
});
But if you want to see who vote in that referendum I suggest you to use the SUBSCAN API, the endpoint /scan/democracy/votes where you can get the voters specifying the referendum ID.
This is what Polkassembly is using to get all the voters. Check their code here.
fetch(`https://kusama.api.subscan.io/api/scan/democracy/votes`,
{
body: JSON.stringify({
page: currentPage,
referendum_index: referendumId,
row: 10
}),
headers: subscanApiHeaders,
method: 'POST'
}).then(async (res) => {
const votersData = await res.json();
if(votersData && votersData.data && votersData.data.list) {
if(!count) {
setCount(votersData.data.count);
}
setVotersList(votersData.data.list);
}
setLoadingStatus({
isLoading: false,
message: 'Loading Data'
});
}).catch((err) => {
console.error('Error in fetching vote data:', err);
});