@deernetwork/type-definitions

Polkadot.js type definations for Deer Network

Usage no npm install needed!

<script type="module">
  import deernetworkTypeDefinitions from 'https://cdn.skypack.dev/@deernetwork/type-definitions';
</script>

README

deer-type-definitions

Usage

This repo contains Typescript bindings for custom deer-node modules.

In order to use the standard API against Deer you must initialize the API's options object as follows:

// We need to import the augmented definitions "somewhere" in our projec
import "@deernetwork/type-definitions/interfaces/augment-api";
import "@deernetwork/type-definitions/interfaces/augment-types";

import { ApiPromise, WsProvider } from "@polkadot/api";
import { ApiOptions } from "@polkadot/api/types";
import { typesBundle } from "@deernetwork/type-definitions";

const options: ApiOptions = {
  provider : new WsProvider('ws://localhost:9944'),
  typesBundle,
};

const api = new ApiPromise(options);

You will also need to update the tsconfig.json of your project to include the following:

{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "@polkadot/types/lookup": ["../node_modules/@deernetwork/type-definitions/interfaces/types-lookup.d.ts"],
    }
  }
}

Dependencies

Your project's @polkadot-js dependency versions must match the versions used in this project, including @polkadot/api, @polkadot/keyring, and all associated packages, as well as rxjs (if using ApiRx instead of ApiPromise) and typescript. To verify the versions required, inspect the @polkadot package.json files for the version specified in this project's package.json.

Building

This project depends on the @polkadot/typegen project, which has a step-by-step guide to building this project.

The Deer-specific version is as follows:

  • Ensure in package.json that @polkadot/api is set to the correct version, and that @polkadot/typegen is set to the same version as @polkadot/api. Increase the @deernetwork/type-definitions version if necessary for publication.

  • Ensure that all the definitions.ts files in src/interfaces are updated to the latest versions of each type, if any deer modules changed.

  • Run an deer-node chain on localhost. Then, run ./generateMetadata.bash to update the deer.json file.

  • Once you have an deer.json file, you can rebuild the types with:

    $ npm run generate
    $ npm run lint
    
  • Upgrade all spec files with any changes necessary as per the @polkadot-js changelog and the underlying Substrate version of the chain.

  • To compile the Typescript to Javascript for npm publication, run node scripts/build.js. This command should not produce any errors and will output build files to the pkg directory.

  • Publish the new version with node scripts/publish.js.