1

I am trying to run one of the examples in the Polkadot{.js} documentation and it is not working for me in TypeScript. This much works

  const wsProvider = new WsProvider('wss://rpc.polkadot.io');
  const api = await ApiPromise.create({ provider: wsProvider });
  console.log(api.genesisHash.toHex());

  const ADDR = '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE';
  const now = await api.query.timestamp.now();
  console.log(`${now}`);

However, this line does not work:

  const { nonce, data: balance } = await api.query.system.account(ADDR);

Here is the error returned:

   return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/scripts/index.ts:110:11 - error TS2339: Property 'nonce' does not exist on type 'Codec'.

110   const { nonce, data: balance } = await api.query.system.account(ADDR);
              ~~~~~
src/scripts/index.ts:110:18 - error TS2339: Property 'data' does not exist on type 'Codec'.

110   const { nonce, data: balance } = await api.query.system.account(ADDR);
                     ~~~~

I don't know if the problem is that I am running it in TypeScript or something else, but does anyone have any suggestions to make this work or see something that I am doing wrong? Thanks.

1

1 Answer 1

1

As a workaround, I was able to use the following code to get the nonce and free balance:

  const data = await api.query.system.account(ADDR);
  console.log(JSON.stringify(data));
  console.log(data['nonce'].toHuman());
  console.log(data['data']['free'].toHuman());

Do you think the online example is outdated?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.