* Custom hook support for indexing on events. * Add fill support. * Process GQL subscriptions. * Add hooks example. * Update hooks example. |
||
|---|---|---|
| .. | ||
| src | ||
| .eslintignore | ||
| .eslintrc.json | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
Code Generator
Setup
-
Run the following command to install required packages:
yarn
Run
-
Run the following command to generate a watcher from a contract file:
yarn codegen --input-file <input-file-path> --contract-name <contract-name> --output-folder [output-folder] --mode [eth_call | storage | all] --flatten [true | false] --kind [lazy | active]input-file(alias:i): Input contract file path or an URL (required).contract-name(alias:c): Main contract name (required).output-folder(alias:o): Output folder path. (logs output usingstdoutif not provided).mode(alias:m): Code generation mode (default:all).flatten(alias:f): Flatten the input contract file (default:true).kind(alias:k): Kind of watcher (default;active).
Note: When passed an URL as
input-file, it is assumed that it points to an already flattened contract file.Examples:
Generate code in both
eth_callandstoragemode,activekind.yarn codegen --input-file ./test/examples/contracts/ERC20.sol --contract-name ERC20 --output-folder ../my-erc20-watcher --mode all --kind activeGenerate code in
eth_callmode using a contract provided by an URL.yarn codegen --input-file https://git.io/Jupci --contract-name ERC721 --output-folder ../my-erc721-watcher --mode eth_callGenerate code in
storagemode,lazykind.yarn codegen --input-file ./test/examples/contracts/ERC721.sol --contract-name ERC721 --output-folder ../my-erc721-watcher --mode storage --kind lazy
Demo
-
In root of the repository:
-
Install required packages:
yarn -
Build files:
yarn build
-
-
Generate a watcher from a contract file:
yarn codegen --input-file ../../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol --contract-name ERC20 --output-folder ../demo-erc20-watcher --mode eth_call --kind activeThis will create a folder called
demo-erc20-watchercontaining the generated code at the specified path. Follow the steps indemo-erc20-watcher/README.mdto setup and run the generated watcher. -
Generate a watcher from a flattened contract file from an URL:
yarn codegen --input-file https://git.io/Jupci --contract-name ERC721 --output-folder ../demo-erc721-watcher --mode all --kind active
References
- ERC20 schema generation (eth_call mode).
- ERC20 schema generation (storage mode).
- ERC721 schema generation (eth_call mode).
- ERC721 schema generation (storage mode).
Known Issues
- Currently,
node-fetch v2.6.2is being used to fetch from URLs asv3.0.0is an ESM-only module andts-nodetranspiles to import it usingrequire.