0

I will try to explain it briefly. I'm using Promise API to connect to few different RPCs (ws). Also I'm listening to an event connected on each websocket provider. When all providers are connected I call res to resolve my new promise that returns in my connectRpcs function. Then in other function I call:

await ApiPromise.create({ provider })

and wait until ApiPromise.create resolves for each provider. When all providers and APIs are set up I'm trying to call api.query.system.account for some rpc from the list and the rpc throws the error:

RPC-CORE: queryStorageAt(keys: Vec<StorageKey>, at?: BlockHash): Vec<StorageChangeSet>:: cannot call send() while not connected

I logged provider.isConnected for each provider and it returns true. Why provider says that I'm not connected to the rpc? any guesses? I can share code in hastebin to clarify some points.

3

1 Answer 1

0

What happens is that trying to make the call api.query.system.account before connect to the node.

Review all the await/async, I have added and async inside of the Promise.all you have in the index.js file and it worked:

const result = await Promise.all(Object.keys(chains).map(chain => {
    (async () => {
        const api = chains[chain];
        /*
            RPC-CORE: queryStorageAt(keys: Vec<StorageKey>, at?: BlockHash): Vec<StorageChangeSet>:: cannot call send()             while not connected
        */
        const { data: balance } = await api.query.system.account('MY ADDRESS')
        return balance.free
    })()
}));
5
  • What's the difference between async chain => {} and your async IIFE?
    – guakamole
    Jan 16, 2023 at 14:43
  • Doesn't work anyways
    – guakamole
    Jan 16, 2023 at 14:43
  • You didn't have the async there, no?
    – Alex Bean
    Jan 16, 2023 at 15:29
  • I had actually. My bad that I rewritten code wrongly
    – guakamole
    Jan 17, 2023 at 0:49
  • Thank you man. I figured out what was wrong. I had no await lol
    – guakamole
    Jan 17, 2023 at 0:50

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.