How to use the @polkadot/api/index.WsProvider function in @polkadot/api

To help you get started, we’ve selected a few @polkadot/api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polkadot-js / api / packages / types / src / scripts / extractChain.ts View on Github external
async function main (): Promise {
  const provider = new WsProvider(ws);
  const api = await ApiPromise.create({ provider });
  const [chain, props] = await Promise.all([
    api.rpc.system.chain(),
    api.rpc.system.properties()
  ]);

  // output the chain info, for easy re-use
  console.error(`// Generated via 'yarn run chain:info ${ws}'\n\nexport default {\n  chain: '${chain.toString()}',\n  genesisHash: '${api.genesisHash.toHex()}',\n  specVersion: ${api.runtimeVersion.specVersion.toNumber()},\n  ss58Format: ${props.ss58Format.unwrapOr(42)},\n  tokenDecimals: ${props.tokenDecimals.unwrapOr(0)},\n  tokenSymbol: '${props.tokenSymbol.unwrapOr('UNIT')}',\n  metaCalls: '${Buffer.from(api.runtimeMetadata.asCallsOnly.toU8a()).toString('base64')}'\n};`);

  // show any missing types
  api.runtimeMetadata.getUniqTypes(false);
}

@polkadot/api

Promise and RxJS wrappers around the Polkadot JS RPC

Apache-2.0
Latest version published 5 days ago

Package Health Score

90 / 100
Full package analysis

Similar packages