Very sorry for such a newbie question; just don't know where else to ask 🙏
Essentially, I want to programmatically dump from the network who won the most recent election. To do so, I'm issuing an erasStakers(...)
[https://polkadot.js.org/docs/substrate/storage/#erasstakersu32-accountid32-palletstakingexposure] RPC call. So far as I understand it, there is no direct RPC API call for erasStakers(...)
, and one needs to interact with the node through getStorage(...)
to learn the election result.
Yet the Polkadot Explorer somehow shows the human-readable output:
However, when I do in my Nodejs code:
await api.query.staking.erasStakers(635, null)
// => {"total":0,"own":0,"others":[]}
It seems the Polkadot Node just returns an empty object.
I also know about Parity's substrate-debug-kit
[https://github.com/paritytech/substrate-debug-kit/blob/master/offline-election/src/subcommands/staking.rs] repo, which queries the Polkadot's node. I believe I could leverage sub_storage::read
from that repo, but I can't guess the correct "Prefix" parameter and the return type to get erasStakers
; it just says "get_pairs failed", whatever I try.
Is there a way to get either in my NodeJS or in my Rust code something akin to what I see in the picture — a human readable structure representing an erasStakers(...)
call?
I'm new to Polkadot, so apologies if I mixed up terms, or misunderstood something trivial — any help would be much appreciated.
await api.query.staking.erasStakers(635, null)
- use.entries
, see polkadot.js.org/docs/api/cookbook/… (that is what the apps UI uses above)state_getStorage
, but it requires to pass the storage key encoded which is not friendly to do by hand but your Rust client should be able to do that for you.