@polkadot/types/types#RegisteredTypes TypeScript Examples

The following examples show how to use @polkadot/types/types#RegisteredTypes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChainInfo.ts    From commonwealth with GNU General Public License v3.0 5 votes vote down vote up
public substrateSpec: RegisteredTypes;
Example #2
Source File: testSubstrateSpec.ts    From commonwealth with GNU General Public License v3.0 5 votes vote down vote up
testSubstrateSpec = async (specString: string, nodeUrl: string) => {
  // test out spec
  // get spec from request
  let unpackedSpec: RegisteredTypes;
  log.info('Parsing spec...');
  try {
    unpackedSpec = JSON.parse(specString);
  } catch (e) {
    throw new Error('Could not parse spec data');
  }
  const sanitizedSpec: RegisteredTypes = {
    types: unpackedSpec['types'],
    typesAlias: unpackedSpec['typesAlias'],
    typesBundle: unpackedSpec['typesBundle'],
    typesChain: unpackedSpec['typesChain'],
    typesSpec: unpackedSpec['typesSpec'],
  };

  log.info('Connecting to node...');
  const provider = new WsProvider(constructSubstrateUrl(nodeUrl), false);
  try {
    await provider.connect();
  } catch (err) {
    throw new Error('failed to connect to node url');
  }
  try {
    log.info('Fetching chain properties...');
    const api = await ApiPromise.create({ provider, ...sanitizedSpec });
    const version = api.runtimeVersion;
    const props = await api.rpc.system.properties();
    log.info(`Fetched version: ${version.specName}:${version.specVersion} and properties ${JSON.stringify(props)}`);
    log.info('Disconnecting from chain...');
    await api.disconnect();
    return sanitizedSpec;
  } catch (err) {
    log.info('Disconnecting from provider in error...');
    await provider.disconnect();
    throw new Error(`failed to initialize polkadot api: ${err.message}`);
  }
}