@supercolony/typechain-polkadot
v0.5.0
Published
---
Downloads
27
Keywords
Readme
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:
- build-extrinsic docs
- constructors docs
- contract docs
- data docs
- events docs
- events-types docs
- mixed-methods docs
- query docs
- tx-sign-and-send docs
- types-arguments docs
- types-returns docs
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'
)