subquery / subql

SubQuery is an Open, Flexible, Fast and Universal data indexing framework for web3. Our mission is to help developers create the decentralised products of the future.
https://subquery.network
GNU General Public License v3.0
19.06k stars 328 forks source link

Indexing fails if we use `ApiPromise` from `@polkadot/api` package. #2502

Closed Niraj-Kamdar closed 1 month ago

Niraj-Kamdar commented 1 month ago

Prerequisites

Description

Here's the code:

import { ApiPromise, WsProvider } from "@polkadot/api";

export async function getApi() {
  const provider = new WsProvider("ws://127.0.0.1:9944");
  const api = await (await ApiPromise.create({ provider })).isReady;
  return api;
}
<WorkerBlockDispatcherService> ERROR failed to index block at height 2565  
subquery-node-1   | Error: Cannot find module 'zlib'
subquery-node-1   | Stack: VMError: Cannot find module 'zlib'
subquery-node-1   |     at CustomResolver.resolveFull (/node_modules/vm2/lib/resolver.js:126:9)
subquery-node-1   |     at CustomResolver.resolveFull (/node_modules/vm2/lib/resolver.js:316:16)
subquery-node-1   |     at CustomResolver.resolve (/node_modules/vm2/lib/resolver.js:121:15)
subquery-node-1   |     at resolve (/node_modules/vm2/lib/nodevm.js:317:21)
subquery-node-1   |     at VM2 Wrapper.apply (/node_modules/vm2/lib/bridge.js:485:11)
subquery-node-1   |     at requireImpl (/node_modules/vm2/lib/setup-node-sandbox.js:90:19)
subquery-node-1   |     at require (/node_modules/vm2/lib/setup-node-sandbox.js:171:10)
subquery-node-1   |     at 3106 (webpack://staking-graphql/external node-commonjs "zlib":1:17)
subquery-node-1   |     at i (webpack://staking-graphql/webpack/bootstrap:19:31)
subquery-node-1   |     at 2971 (webpack://staking-graphql/node_modules/ws/lib/permessage-deflate.js:3:13)
subquery-node-1 exited with code 1

Reference: https://academy.subquery.network/indexer/academy/herocourse/module6.html#block-v-events-v-calls

Details

These details can help to reproduce the environment the issue is occurring

Local Environment: docker: subquerynetwork/subql-node-substrate:latest Query Version: docker Indexer Version: docker Network Details:

Steps to Reproduce

Example project: try with substrate starter and make any API calls Expected behavior:Should index Actual behavior: throwing error

stwiname commented 1 month ago

Hi @Niraj-Kamdar the API is injected globally so you don't need to construct your own instance.

https://academy.subquery.network/indexer/build/mapping/polkadot.html#rpc-calls