paritytech/substrate-connect

Question: What is ScConnect in `ScProvider`

vatsa287 opened this issue · 0 comments

Went through the doc example and tried to connect to a custom chain.
But the documentation example is not covering SubstrateConnect requirement as a first parameter in const provider = new ScProvider(customSpec);

Please suggest the usage of substrate-connect.

import { ScProvider, WellKnownChain, SubstrateConnect } from "@polkadot/rpc-provider/substrate-connect";
import { ApiPromise } from "@polkadot/api";
import jsonCustomSpec from "./jsonCustomSpec.json";

async function main() {
  const customSpec = JSON.stringify(jsonCustomSpec);
  
  const provider = new ScProvider(customSpec);
  
  await provider.connect();

  const api = await ApiPromise.create({ provider });

  await api.rpc.chain.subscribeNewHeads(lastHeader => {
    console.log(lastHeader.hash.toString());
  });

  await api.disconnect();
}

main().catch(console.error);

How and what to be used for sc: SubstrateConnect for below,

(alias) new ScProvider(Sc: SubstrateConnect, spec: string, sharedSandbox?: ScProvider | undefined): ScProvider
import ScProvider

My error is as below

Error: Expected an @substrate/connect interface as first parameter to ScProvider
    at new ScProvider (/Users/vatsa/cord.js/node_modules/@polkadot/rpc-provider/cjs/substrate-connect/index.js:36:19)
    at main (/Users/vatsa/cord.js/demo/src/test2.ts:8:20)
    at jsonCustomSpec (/Users/vatsa/cord.js/demo/src/test2.ts:21:1)
    at Object.<anonymous> (/Users/vatsa/cord.js/demo/src/test2.ts:21:27)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Object.S (/Users/vatsa/cord.js/node_modules/tsx/dist/cjs/index.cjs:1:1292)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at cjsLoader (node:internal/modules/esm/translators:356:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:305:7)

Thanks.