1

According to the documentation, api.query.nominationPools.poolMembers should yield details about pool members.

The result should be a Map so we should be able to iterate the .entries / .keys.

(async () {
  const provider = new WsProvider('wss://kusama-rpc.polkadot.io')
  const api = await ApiPromise.create({ provider: provider })

  var addresses = [
    'F3opxRbN5ZavB4LTn2JaUnScQc7G7G177CPnqjBpa9F9Gdr', // pool 50 stash
    'F3opxRbN5ZavB4LTn2aKWL2iuHJifMsqn8uLnR2HQ1yQs7t', // pool 50 reward
    'HhYuQCR1pJKVwPruCSNr8xp4R1ovqtAbNy3S8VuMXsPtBmH', // pool 50 depositor/root/etc
  ]

  addresses.forEach(async (address) => {
    console.log('address', address)
    var members = await api.query.nominationPools.poolMembers.entries(address)
    var keys    = await api.query.nominationPools.poolMembers.keys(address)
    
    console.log('members', members, 'keys', keys)
    // const accountIds = keys.map(({ args: [accountId] }) => accountId)
    const accountIds = keys.map(({ args }) => args)
    console.debug('accountIds', accountIds)

    members.forEach(([key, member]) => {
      console.log('key arguments:', key.args.map((k) => k.toHuman()));
      console.log('     exposure:', member.toHuman());
    })
  })
})()

However, I can't get anything from the entries() or keys()

returns

address F3opxRbN5ZavB4LTn2JaUnScQc7G7G177CPnqjBpa9F9Gdr
address F3opxRbN5ZavB4LTn2aKWL2iuHJifMsqn8uLnR2HQ1yQs7t
address HhYuQCR1pJKVwPruCSNr8xp4R1ovqtAbNy3S8VuMXsPtBmH
done...
members [] keys []
accountIds []
members [] keys []
accountIds []
members [] keys []
accountIds []

Just calling await api.query.nominationPools.poolMembers(POOL_ADDRESS) produces:

    {
        "poolId" : 34,
        "points" : 1011793913984.0,
        "rewardPoolTotalEarnings" : 449109804460.0,
        "unbondingEras" : {}
    },

1 Answer 1

5

It is a map. So to get .entries() you specify no parameters as per the docs. Params would only come into play with higher-order maps as per docs.

To get all the entries of the pools -

const e = await api.query.nominationPools.poolMembers.entries()

e.forEach(([k, v]) =>
  console.log(
    /* AccountId */
    k.args[0].toString(),
    /* Pool info */
    JSON.stringify(v.toHuman())
  )
)

Which would look like something like the following on Kusama -

GyBph4GJZsiMNJv53mACcujkWcm8NvWF7o2s2pf6PU1efh1 {"poolId":"46","points":"100,000,000,000","rewardPoolTotalEarnings":"10,378,313,014","unbondingEras":{}}
Fk5Z52gA8Ue5G3jNWtvJzNARU1HK12ufsa5xZuDgKvQK5KX {"poolId":"43","points":"1,000,000,000,000","rewardPoolTotalEarnings":"91,827,296,941","unbondingEras":{}}
GUiPpM5wF4KhEiTt2emUYB9VpBSuyEPYhRsE15Ur75Q4ToM {"poolId":"54","points":"5,000,000,000,000","rewardPoolTotalEarnings":"1,713,575,059","unbondingEras":{}}
EFQ1wXD4X1KvV68Ks9VsM2XEjrGZhZo14sjSLQndCTgTRrU {"poolId":"2","points":"2,138,360,777,446","rewardPoolTotalEarnings":"9,324,915,743,936","unbondingEras":{}}
G5NLBLGAUgozcXseaWSsCpfXnxqHcSW7nAAZ689PvspThnE {"poolId":"34","points":"500,000,000,000","rewardPoolTotalEarnings":"562,215,251,310","unbondingEras":{}}
DE1QQkVPp8XVksN4v6qnQYWUjMBBrPGLkHtHM4zZ8N9Vmoc {"poolId":"5","points":"1,000,000,000,000","rewardPoolTotalEarnings":"0","unbondingEras":{}}
FaJi8E1WkeGDR7f79SyburcAkzh78X587diwWhKezDxn1p8 {"poolId":"1","points":"35,000,000,000,000","rewardPoolTotalEarnings":"300,374,601,212","unbondingEras":{}}
JKYYceWYMAoJMEw9CJWMxmfA7fZbc3he9JKDt7ivYvKXmkq {"poolId":"7","points":"6,000,000,000,000","rewardPoolTotalEarnings":"0","unbondingEras":{}}
...
1
  • 1
    Ok, I see it now. So GyBph4GJZsiMNJv53mACcujkWcm8NvWF7o2s2pf6PU1efh1 is a member of 46... and so on. We just need to iterate the entries and filter for the pool ID. Thanks!
    – DerekC
    Aug 12, 2022 at 12:35

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.