polkadot-js / api

Promise and RxJS APIs around Polkadot and Substrate based chains via RPC calls. It is dynamically generated based on what the Substrate runtime provides in terms of metadata.
Apache License 2.0
1.07k stars 354 forks source link

Cannot read properties of undefined (reading 'toHuman') #5875

Closed ioannist closed 6 months ago

ioannist commented 6 months ago

for events and extrinsics: GenericExtrinsic<AnyTuple> EventRecord.event: Event calling e.toJSON() works fine

calling e.toHuman()

 error: Error: Error in processBlockRange pipe: Error: Error in fetchBlockData: TypeError: Cannot read properties of undefined (reading 'toHuman')
      at file:///root/stakexyz-worker/indexer-activities/src/indexer.ts:138:48
      at Observable.init [as _subscribe] (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/observable/throwError.js:8:64)
      at Observable._trySubscribe (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Observable.js:41:25)
      at /root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Observable.js:35:31
      at Object.errorContext (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9)
      at Observable.subscribe (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Observable.js:26:24)
      at /root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/operators/catchError.js:17:31
      at OperatorSubscriber._this._error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:43:21)
      at Subscriber.error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:60:18)
      at Subscriber._error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:84:30)
      at Subscriber.error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:60:18)
      at Subscriber._error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:84:30)
      at Subscriber.error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:60:18)
      at Subscriber._error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:84:30)
      at Subscriber.error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:60:18)
      at Subscriber._error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:84:30),
  durationMs: 1673
}

This used to work in v10.11.2 and i think it broke in 10.13.1

TarikGul commented 6 months ago

Can you provide a reproducible example, that would help a lot with narrowing this down.

ioannist commented 6 months ago

Can you provide a reproducible example, that would help a lot with narrowing this down.

import { ApiPromise, WsProvider } from "@polkadot/api";
import { Vec } from "@polkadot/types";
import { EventRecord } from "@polkadot/types/interfaces";

(async () => {
  try {
    console.log('Results to-> TypeError: Cannot read properties of undefined (reading \'toHuman\') in >=10.13.1')

    const provider = new WsProvider('wss://moonbeam.unitedbloc.com');
    const api = await ApiPromise.create({ provider, throwOnConnect: true });

    for (let blockNumber = 1000000; blockNumber < 1001000; blockNumber++) {
      const hash = await api.rpc.chain.getBlockHash(blockNumber);
      const apiAt = await api.at(hash);

      const allRecords = await apiAt.query.system.events() as Vec<EventRecord>;

      for (const record of allRecords) {
        record.event.toHuman()
      }

      const signedBlock = await api.rpc.chain.getBlock(hash);

      for (let extrinsicIndex = 0; extrinsicIndex < signedBlock.block.extrinsics.length; extrinsicIndex++) {
        const extrinsic = signedBlock.block.extrinsics[extrinsicIndex];
        extrinsic.toHuman()
      }
    }
  } catch (err) {
    console.error(err)
    throw err;
  }
})();
TarikGul commented 6 months ago

Fix will be included in Mondays release

polkadot-js-bot commented 6 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.