Skip to content

Repository files navigation

Summary

This package allows you generate a valid OverrideTypesBundle JSON file to inject into a polkadot-js ApiPromise under the typesBundle option key. This is a helper library that works specifically with polkadot-js. It is important to note that this library extracts chain types that are available via apps-config, if the chain types dont exist there it wont be able to support to bundle you need. Example packages that use this implicitly leverage this library are Substrate-api-sidecar, and Txwrapper-core.

Installation

NPMnpm install -g @substrate/generate-type-bundle

Yarnyarn global add @substrate/generate-type-bundle

CLI

Options:
--help Show help [boolean]
--version Show version number [boolean]
-p, --path Path to directory to generate Type files into. [string]
-s, --specName A chain to generate types for. If this is not inputted
it will create a types bundle for all chains. [string]
-a, --availableChains List all available chains to generate types for.

Note: -p or --path is required.

Example CLI usage

Generating a Types Bundle to a specific path

-p or --path:

generate-type-bundle -p "path-to-directory"

Note: This flag is required. The CLI will not generate any types bundles without specifying a directory.

Generate a Types Bundle for a specific chain

-s or --specName:

generate-type-bundle -p "path-to-directory" -s moonbeam

List Available Chains

-a or --availableChains:

generate-type-bundle -a

Example Usage

Polkadot-js

import{ApiPromise}from'@polkadot/api';constmain=async()=>{constapi=awaitApiPromise.create({provider: newWsProvider('ws://127.0.0.1:9944'),typesBundle: require('path-to-file.json')});};

Substrate-api-sidecar

It is recommended to declare these env variables within a local .env file, but the below is an example usage from the terminal directly.

$ export SAS_SUBSTRATE_TYPES_BUNDLE=<path_to_file>
$ substrate-api-sidecar

About

No description, website, or topics provided.

Resources

Security policy

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages