0

I'm trying to utilize the Polkadot.JS api to query chain parameters and issue transactions under collatorSelection an example of which is:

const x = api.query.collatorSelection.candidates();
console.log(x)

This works when using the built in playground in Polkadot.JS/apps but doesn't work via api. I am using v9.9.1 of the API.

0

1 Answer 1

1

This code works fine for me (using the PolkadotJS API):

import { ApiPromise, WsProvider } from "@polkadot/api";

export const fetchCollatorCandidates = async () => {
    const provider = new WsProvider("wss://karura.api.onfinality.io/public-ws");
    const api = new ApiPromise({ provider });
    await api.isReadyOrError;

    const candidates = await api.query.collatorSelection.candidates();
    console.log(candidates.toHuman())
}

Output:

[
  'ofbMGzDpuJttjypUk7SsV4n1omwSxA2gKYXSEDM3gMahNuN',
  'op7G2ofug2Q2n1Bq3uUGzkNdSp68S93beMQkjjyDxnPREnk',
  'qyf2KVDbBmF3MjRgmyFpQrNUnoxhp9AWCJrywysQcwXaiyb',
  'raCf56Liw9dKJiqXSJMVoVV9eyV9s8DQoQD5r1TMcPoFM4B',
  'rwGFKTBauckjEieq3xauaiDXxjfarZ198KXXVZupa9Dr6xm',
  'sBwVWToF55CbuyBz3WEqDggniu8Gx18DkTQg4cagsCJsgVf',
  'sgxpvRrL2VpAqhLPqC9up2u7gf1pCpR9c8vB7XdxnBpjxUC',
  't4HMEqx3kW8ADAzKn5YWhAUQPdsZw7xFd39WLxRW193HYfh',
  'tbjKCiq9k2p6L4xLJ9H7mAHs8FBE76aG4KcDapUbUnifjnr',
  'tyBG83iCBH5zAx7zd3kvTzEJAGY8nuH2HsTtvf6YwCSwwVL'
]
1
  • 1
    Thanks for sharing this @Bruno. My application used two api connections, one on the relay chain and the other on the parachain. Due to my error I passed the relay chain api connection to a function requiring a parachain api connection. Given the code above I established that functionality exists and was able to find the error from there. Thanks for taking the time. Commented Nov 24, 2022 at 1:27

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.