2

How can i fetch the list of all collators with their names? For example here I can get the count of collators

const totalCollators = await api.query.parachainStaking.totalSelected(); 

Furthermore, where can I find the documentation of these queries? for example what objects api.query.parachainStaking returns.

Thanks.

1 Answer 1

3

Since you didn't mention what chain you were asking about. I'm assuming the chain is Moonbeam network.

According to https://docs.moonbeam.network/node-operators/networks/collators/activities/, you need api.query.parachainStaking.candidatePool to get the list of collator addresses. Additionally you need to pass each address to api.query.identity.identityOf and extract the name info. Here is the full script:

// get list of collator addrs let collatorAddrs = (await api.query.parachainStaking.candidatePool()).map(([x])=>x[1].toString()); // get list of collator names let collatorNames = (await Promise.all(collatorAddrs.map((c)=>api.query.identity.identityOf(c)))).map(x=>x.toHuman()?.info.display.Raw); // zip two lists and construct a mapping from addr to it's name let result = Object.fromEntries(collatorAddrs.map((c, i)=>[c, collatorNames[i]])); // print result console.log(result) 

Here is the output

{ '0x0198D3053a69C3f977bB1943bc95A0fFA7777474': '0xf09f9099205374616b655371756964', '0x01bB6ce8b88F09A7D0BFB40eFf7f2aD5e0DF2e98': 'Foundation-02', '0x021cd61168a50b3b0252A251878e8f81F8f9cb37': 'LetzBake!', '0x02B8d54a9a7b4F408A5d46d7f9fF1B5f1D370504': 'ACV & ORANGE | GIVEAWAY!', '0x0663AA7BEb6a9229Fc5A016ffc81C0F133442A54': 'bitcoinsuisse.com 2', '0x068c67fa2c877B8EB0CE37a0f77617330eB04e72': 'Staker Space', '0x0a0952E7d58817C40473D57a7E37f188DdB81ff9': 'luckyve', '0x10023fA70Ed528E4F28915bf210f6e87b057c08E': 'Sik | crifferent.de', '0x111141269142D8A1BC8F949bFFf7dF227EE8d76A': 'MoonEntropy', '0x13a61daC75e2F66721dcaEdA726be1E636928800': '0xf09f94b14d61737465726e6f646532342e6465', '0x19A33caD2d311830550B41165d5faBf578347f3A': 'Blockdaemon', '0x1Ade25b8679c39a755DB598b2Cf98c36EE86f4fD': 'Bogosort', '0x1C86E56007FCBF759348dcF0479596a9857Ba105': 'PureStake-03', '0x1d4dD1bd8D1F26B631b69396a9cbF7BF7c373073': 'pathrocknetwork', '0x1Dc2Ae28998dcBcD496a96883552bd0fEBC4af32': 'DarkWing', '0x2185e7531A57C45416C78D2cC3B1C768Df6395F0': 'The Milky Way Gang', '0x293d1253b07c8bEB88A3a0758f8E9CCE299841B8': undefined, '0x3431e0dE19a9eB54d71bE71a2FDdB7e7b3225643': 'CertHum Inc.', '0x35ac93AeDb902440154Cd90d6c1c25884775bF46': 'High Stakes', '0x3f0937BdEF510fd1D39F76CF41a7A4CFbf8ab876': 'Polkadotters', '0x4FAdbd3A6E6Ff1cd17aDa64EB79Be168Ce32cF7c': 'Simply Staking 03', '0x564E8464A616baE3c366467eD572C3d2Ae8b9E63': 'Simply Staking', '0x579279366aF138CA8b8A467F8aa8bc7e03D314f9': 'Source', '0x58587E945c161f5c98c20BF2e7eec135f0a5D676': 'Ondin', '0x5C68Ce6100f980Ced708bD89CCE028840Ac6bDA9': 'LEGEND', '0x5d6D1a59Fd3E6cf325FACCbEA4d1265b15d34aCB': 'bitcoinsuisse.com 3', '0x5D9Bc481749420CFFB2BF5aeF5c5e2A0fFe04e88': '0xe29c88efb88f2055544f5049412026204d6f6f6e506574732e617070', '0x64265707F81633Fb7b871083DddBb5d04f5c7af7': 'PureStake-04', '0x6Ac4b6725eFD8a1CB397884769730094e854efd4': '0xf09f9bb8205a6f6f70657220436f727020f09f9bb8', '0x6F21E1C5234eC2DA8019632d4836fFCC2379DbA7': undefined, '0x6faf9F07D12D68A3685d34F3262383df40Bd35Cd': '255 DAO 02 | 2555 GLMR GIVEAWAY', '0x703dF467FE6Ef01868D16fD7230C8E72fe2F7fEF': 'moonli.me', '0x73Fd06aBCa1669725CE4ecA539bf55393B228f23': 'ZKValidator', '0x7A6a051d542040155c41eB599e995427bf672b4d': 'DomiNodes', '0x7f1f9A444A22d8d39EfdFdD9c441070F36a20750': 'Simply Staking 02', '0x7fA2033272db2E4116CE314fd789A3A148F2Ed55': 'Brightlystake', '0x834e4E90718673CbC3508a29877b20C5C2bA2417': undefined, '0x84F94DA49C63596Cb9a465b02e65F43CA2315041': 'bitcoinsuisse.com 1', '0x8730b791EE9Fd8abF80Caa654f4E4c5626dDbeee': '0x4c45542753204e4f444520262043525950544f52f09f9589', '0x88848d6A768adfaE32C9aef05D70C522893efa1C': 'SmartMoney', '0x890fF0DD8e4cA7141482b4b20D277bb9051c1477': undefined, '0x8C599E8f9B5d15d3Adf89D856f34fFEC8De0B2c6': 'bitcoinsuisse.com 4', '0x9436CF1090cA39e38FEc1F78C01Ac9F936e36965': 'Figment', '0x95a4fB297433C78D0De956CE7eda4CF9EFf9AaF3': undefined, '0x9CED08E436a468668Caa25E0A7907aCF5588d595': 'BloClick', '0x9eEA5Bc566031840743E3eFc8f7919fC393E1573': 'Cosmoon | Stake & Giveaway', '0xa1e5E3C161Bceb944b655364a6848F47c6e93b56': '0x4561726e5820f09f929720426f6e75732052657761726473', '0xA345728816d83533a24BF1d980009F3B01CeC2fe': 'MoonWorld', '0xaA795bB2c69B1419c4e0b56706777e9a68bac42b': undefined, '0xAb4B115b2D23EF8DA7b0aa54FC074fB4C6886441': '0xf09f91b6205374616b6542616279207c204469766572732056616c204e6574', '0xABbed75d32F138E6B3366613dcd01a96E8B61B58': '0x53656e644974205374616b696e67f09f9a80', '0xb15F8D5c222C5998451f34882e3dA4Ad5C2B3165': 'binance-staking-1', '0xb3E64EF8Fc9dF438c9A54f4B189EDdC1807b55a5': 'Foundation-01', '0xb6758E748F5D76B8b1264F9B907D8675DA52c97C': 'Binary Holdings', '0xB9662Aa0aDBF57d5B74Cf39b621e90e45982749e': 'GPvalidator', '0xbA360F50Eb4B68F384C5d4eE4fD1bFbe50D5208b': '0x4d6f6f6e6265616d20f09f8c9420426f6e75732052657761726420313025', '0xbb43c8F298ddB8094529b9708C53b732B3eDbB6a': '0xe29c88efb88f2055544f504941202620544620414c504841', '0xbD8027E8463843911Ed5503f339C992E728BD471': 'Moonbean', '0xC26694a78039548b9AeE363b1e12dEb0F98f44Dc': 'Bware Labs', '0xC38bCF2eed198E072a92E66435Dd1157364C3e7c': 'BerryStake', '0xc54f704CeC71381097341B213939c73a63af1b6e': 'Moon Landing', '0xCA98D4378393040408100f490bF98b03F5E7DeB7': '0xf09fa78a2049636562657267204e6f64657320f09fa78a', '0xCb4B3bf2D527f42368C0b4e17Aa894E348Fc1806': 'Sio34', '0xD3dfa1Fc4e5BB0a268cE149F6c5c2dEc5a4083Ce': 'Simply Staking 04', '0xd53f505dD7C6775b86C98998D4ff18EbBbe0c430': '0x4d41582041495244524f50f09f9a8036303030474c4d52204749564541574159', '0xD7d1E0593c437aBf982e297aF27e42ABffc072B4': 'Mission Control - Polka Haus', '0xd9FFaB42F9a2De10C2c920eB8D333e01CD5FB4a6': 'TrueStaking', '0xdD760A8f8ce5E4B5f9Ff436EE7790c603D6294d0': 'Hetavalidation', '0xe22d73F5dcCCb31a994Ad4E7AD265Cf69B4E725A': 'PureStake-02', '0xE596665a52D9Bb37865b3a9264fFE038Be08F28d': '255 DAO 01 | 2555 GLMR GIVEAWAY', '0xe751B9EA560A200161d1B70249495E3d22Ec5b00': 'Foundation-03', '0xeA9Bf34D0294e1008C0D22F59e095Eae63a53155': 'DeYure', '0xeCca07badBd38937122B82ec8AfCf86b1E2b7939': 'TECH NINJA', '0xF02ddb48EdA520C915c0dABADC70BA12D1b49ad2': 'Foundation-04', '0xf5fE1e0f92A2d7a8e0d848E8327e24fFfD2718a3': 'PureStake-01', '0xFBB4f5E6649bF46177728F6aEA048EfEE640a706': undefined, '0xFc1084962DE75E1480bbbb5a0909fE8e1498977d': 'ALFASTAKE' } 

The result may change as time passes. You should rerun the snippet in order to get the latest result.

Answering the second part of the question. The polkadot.js library has many undocumented parts. However you can always manually inspect the api's metadata and see a list of all methods along with their descriptions. Another tip is to use the node.js repl when you are exploring an unfamiliar library. For polkadot.js there's a specific tool made for that purpose called SubShell.

1
  • Thanks it's helpful Commented Jun 18, 2022 at 12:03

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.