0.5.0 • Published 2 years ago

@supercolony/typechain-polkadot v0.5.0

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

Typechain-polkadot


Package for generating TypeScript definitions & runtime code for Polkadot smart contracts.


Usage

In your project install this package:

npm i -D @supercolony/typechain-polkadot

Now you can use it to generate TS definitions & runtime code for Polkadot smart contracts. To use typechain-polkadot.

Typechain can be used in two ways:

  • As a CLI tool
  • As a library

CLI tool

After installing the package, you can use it as a CLI tool. To use it, run the following command:

npx @supercolony/typechain-polkadot --input path/to/abis --output path/to/output

Library

You can also use typechain-polkadot as a library. To use it, you need to import it in your code:

import {Typechain} from '@supercolony/typechain-polkadot/src/types/typechain';
import {testPathPatternToRegExp} from "jest-util";

const typechain = new Typechain();

typechain.loadDefaultPlugins();

typecchain.run(
	pathToInput,
	pathToOutput
)

Plugins

Typechain-polkadot uses plugins to generate code. By default, it uses the following plugins:

You can also create your own plugins. To do this, you need to create a class that implements the TypechainPlugin interface:

import {TypechainPlugin} from '@supercolony/typechain-polkadot/src/types/interfaces';

export class MyPlugin implements TypechainPlugin {
  constructor() {}

  name: string = 'my-plugin';
  outputDir: string = 'my-plugin';

  generate: (
  	abi: Abi,
	fileName: string,
	absPathToABIs: string,
	absPathToOutput: string
  ): void {
      // generate code
  }

  beforeRun ?: (
      absPathToABIs: string,
	  absPathToOutput: string
  ) => void {
      // do something before run
  }
}

Then you need to add your plugin to the list of plugins:

typechain.loadPlugins(new MyPlugin());

Or you can load them via cli:

npx @supercolony/typechain-polkadot --input path/to/abis --output path/to/output --plugins ./plugins-directory

Also you can use loadPluginsFromFiles method to load plugins from files:

typechain.loadPluginsFromFiles(
	'./plugins'
)
0.4.9

2 years ago

0.4.8

2 years ago

0.4.10

2 years ago

0.4.11

2 years ago

0.4.7

2 years ago

0.5.0

2 years ago

0.3.6-beta.1

2 years ago

0.3.7-beta.1

2 years ago

0.3.6-beta.5

2 years ago

0.3.6-beta.4

2 years ago

0.3.6-beta.3

2 years ago

0.3.6-beta.2

2 years ago

0.4.5

2 years ago

0.3.6-beta.9

2 years ago

0.4.4

2 years ago

0.3.6-beta.8

2 years ago

0.3.6-beta.7

2 years ago

0.4.6

2 years ago

0.3.6-beta.6

2 years ago

0.4.1

2 years ago

0.3.6-beta.10

2 years ago

0.4.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.1.1

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago