Until now, to follow the referendums through the polkadot.js api, I was using storage methods that are part of the default Substrate runtime (located here: https://polkadot.js.org/docs/substrate/storage) But by coming gov2 and transferring the Kusama referendums to it, I cannot track the referendums through previous methods. How can i use these methods in gov2 ?
1 Answer
You can still query all the democracy storage to get all the referendums.
You can get some indexes with:
/* The next free referendum index */
const nextFreeIndex = await api.query.democracy.referendumCount();
/* The lowest referendum index representing an unbaked referendum */
const lowestUnbaked = await api.query.democracy.lowestUnbaked();
And with this index get a specific referendum:
const lastReferendum = await api.query.democracy.referendumInfoOf(lowestUnbaked);
console.log(lastReferendum.toHuman());
And to get the number of (public) proposals that have been made so far:
const proposalsCount = await api.query.democracy.publicPropCount();
console.log(proposalsCount.toHuman());
With that we are getting all the information you can see in the image below (Kusama governance right now):
If you want to get all the referendums (Finished and OnGoing) you can do it with this little script:
const allEntries = await api.query.democracy.referendumInfoOf.entries();
allEntries.forEach(([{ args: [id] }, referendum]) => {
console.log(`${id}: Referendum: ${JSON.stringify(referendum.toHuman())}`);
});
For more information check the democracy docs.