1

I'm building an automation for the Gov2 referenda module, testing right now using wss://governance2-testnet.litentry.io test network with polkadot.js app

Differently from what the democracy module we currently have in Polkadot and Kusama, I cannot retrieve anymore the list of who is currently voting on what. Not even from the api calls. Am I missing something ? or is the new system supposed to not store that information anymore?

Before enter image description here

After enter image description here

1
  • can you please be more specific about what queries and code you are using, and what expected output you want?
    – Shawn Tabrizi
    Commented Nov 12, 2022 at 20:40

2 Answers 2

2

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);
        });
4
  • this is for gov 1.0 isn't it? Commented Jan 20, 2023 at 5:59
  • In the Polkadot network is still gov 1.0 yes, but in Kusama gov 2.0 is deployed already
    – Alex Bean
    Commented Jan 20, 2023 at 8:22
  • But when I do await api.query.democracy.referendumInfoOf.entries() as recommended, I only see the list of gov 1.0 referenda. Commented Jan 20, 2023 at 16:59
  • It should get you for Gov2 too, check kusama.polkassembly.io where you can switch from Gov1 to Gov2. After run await api.query.democracy.referendumInfoOf.entries() you can see in the list the gov2 too
    – Alex Bean
    Commented Jan 23, 2023 at 8:44
1

We can get the final blocks of each referendum by calling Referenda.ReferendumInfoFor storage function, and then for each referendum and respective final block, make a call to ConvictionVoting.VotingFor and parse all the votes for the referendum in question. For ongoing referenda we just pass the chain head.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.