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();

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.


1 Answer 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();


  • 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.