aboutsummaryrefslogtreecommitdiffstats
path: root/packages/abi-gen/README.md
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-12-06 06:18:36 +0800
committerFabio Berger <me@fabioberger.com>2017-12-06 06:18:36 +0800
commit08168c6e7d52711aeb46e27444ba26970e16e244 (patch)
tree40a006de279221009d0ee05d73bfbb74f0a9ea91 /packages/abi-gen/README.md
parentb5030df4e3afe17b4e652b438d655edda79c5f54 (diff)
parent4441d76725af4e83f90eeb373983b600b6903e8e (diff)
downloaddexon-sol-tools-08168c6e7d52711aeb46e27444ba26970e16e244.tar
dexon-sol-tools-08168c6e7d52711aeb46e27444ba26970e16e244.tar.gz
dexon-sol-tools-08168c6e7d52711aeb46e27444ba26970e16e244.tar.bz2
dexon-sol-tools-08168c6e7d52711aeb46e27444ba26970e16e244.tar.lz
dexon-sol-tools-08168c6e7d52711aeb46e27444ba26970e16e244.tar.xz
dexon-sol-tools-08168c6e7d52711aeb46e27444ba26970e16e244.tar.zst
dexon-sol-tools-08168c6e7d52711aeb46e27444ba26970e16e244.zip
Merge branch 'development' into feature/addSubproviders
* development: (50 commits) Add PR number to changelog Address feedback Add requestId to subscription messages and update json-schemas Remove isomorphic-fetch types from contracts package Update README Regenerate files Make it private Change package name Update README Make fileExtension configurable Rename abi-gen to typed-contracts Add docs for typed-contracts Remove TODOs Introduce separate ContextData type and rework it Check ABI is defined Introduce a const for 'contract.mustache' Improve error message Reuse util Fix a typo Introduce a const for 'function' ... # Conflicts: # yarn.lock
Diffstat (limited to 'packages/abi-gen/README.md')
-rw-r--r--packages/abi-gen/README.md40
1 files changed, 40 insertions, 0 deletions
diff --git a/packages/abi-gen/README.md b/packages/abi-gen/README.md
new file mode 100644
index 000000000..f1f8bd08f
--- /dev/null
+++ b/packages/abi-gen/README.md
@@ -0,0 +1,40 @@
+# ABI Gen
+
+This package allows you to generate contract wrappers in any language from ABI files.
+It's heavily inspired by [Geth abigen](https://github.com/ethereum/go-ethereum/wiki/Native-DApps:-Go-bindings-to-Ethereum-contracts) but takes a different approach.
+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 an 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/abi-gen-templates) are the templates used to generate those files.
+
+## Instalation
+`yarn add -g abi-gen`
+## Usage
+```
+abi-gen
+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]
+ --fileExtension The extension of the output file [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 example 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](http://truffleframework.com/) contract artifact (a JSON object with an 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/abi-gen-templates) and start 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 a 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 because it 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/abi-gen/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 file names. If you already have some files in that folder they will be overwritten.