diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-12-05 23:47:39 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-12-05 23:49:24 +0800 |
commit | 63b1199bd545b9f37481fdb8707c0acc49c4d4c3 (patch) | |
tree | fb84a707611c3ab5932a831d023d737e1ea91cc6 /packages/typed-contracts/README.md | |
parent | e2ef7a74dbca24cc18b0c331497812cdc3c221fd (diff) | |
download | dexon-0x-contracts-63b1199bd545b9f37481fdb8707c0acc49c4d4c3.tar dexon-0x-contracts-63b1199bd545b9f37481fdb8707c0acc49c4d4c3.tar.gz dexon-0x-contracts-63b1199bd545b9f37481fdb8707c0acc49c4d4c3.tar.bz2 dexon-0x-contracts-63b1199bd545b9f37481fdb8707c0acc49c4d4c3.tar.lz dexon-0x-contracts-63b1199bd545b9f37481fdb8707c0acc49c4d4c3.tar.xz dexon-0x-contracts-63b1199bd545b9f37481fdb8707c0acc49c4d4c3.tar.zst dexon-0x-contracts-63b1199bd545b9f37481fdb8707c0acc49c4d4c3.zip |
Add docs for typed-contracts
Diffstat (limited to 'packages/typed-contracts/README.md')
-rw-r--r-- | packages/typed-contracts/README.md | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/packages/typed-contracts/README.md b/packages/typed-contracts/README.md new file mode 100644 index 000000000..5649af0dd --- /dev/null +++ b/packages/typed-contracts/README.md @@ -0,0 +1,38 @@ +# Typed contracts + +This package allows you to generate TS contract wrappers from ABI files. +You can write your custom handlebars templates which will allow you to seamlessly integrate the generated code into your existing codebase with existing conventions. + +For the example of the generated [wrapper files](https://github.com/0xProject/0x.js/tree/development/packages/0x.js/src/contract_wrappers/generated) check out 0x.js. +[Here](https://github.com/0xProject/0x.js/tree/development/packages/typed-contracts-templates) are the templates used to generate those files. + +## Instalation +`yarn add -g @0xproject/typed-contracts` +## Usage +``` +typed-contracts +Options: + --help Show help [boolean] + --version Show version number [boolean] + --abiGlob Glob pattern to search for ABI JSON files [string] [required] + --templates Folder where to search for templates [string] [required] + --output Folder where to put the output files [string] [required] +``` +## ABI files +You're required to pass a [glob](https://en.wikipedia.org/wiki/Glob_(programming) template where your abi files are located. +TL;DR - here is the exmaple from 0x.js. + +`--abiGlob 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry).json` + +We could've just used `--abiGlob 'src/artifacts/*.json` but we wanted to exclude some of the abi files. + +The abi file should be either a truffle contract artifact (a JSON object with the abi key) or a JSON abi array. +## How to write custom templates? +The best way to get started is to copy [0x.js templates](https://github.com/0xProject/0x.js/tree/development/packages/typed-contracts-templates) and start playing with them adjusting them for your needs. +We use [handlebars](handlebarsjs.com) template engine under the hood. +You need to have a master template called `contract.mustache`. it will be used to generate each contract wrapper. Although - you don't need and probably shouldn't write all your logic in a single template file. You can write [partial templates](http://handlebarsjs.com/partials.html) and as long as they are within partials folder - they will be registered and available. +## Which data/context do I get in my templates? +For now you don't get much on top of methods abi and a contract name cause if was enough for our use-case, but if you need something else - create a PR. +[Type definition](https://github.com/0xProject/0x.js/tree/development/packages/typed-contracts/src/types.ts) of what we pass to a render method. +## Output files +Output files will be generated within an output folder with names converted to camel case and taken from abi files names. If you already have some files in that folder they will be overwritten. |