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.
Codec
. See this for the solution - polkadot.js.org/docs/api/…