watcher-ts/packages/codegen
Ashwin Phatak 0a96bbd94d
Change dependencies version to be same in all packages. (#250)
Co-authored-by: nabarun <nabarun@deepstacksoft.com>
2021-09-21 10:27:34 +05:30
..
src Use flatten function and modify ResultEvent in schema. (#247) 2021-09-17 17:10:08 +05:30
.eslintignore CLI to flatten and generate GQL schema from Solidity file (#245) 2021-09-16 17:06:10 +05:30
.eslintrc.json CLI to flatten and generate GQL schema from Solidity file (#245) 2021-09-16 17:06:10 +05:30
package.json Change dependencies version to be same in all packages. (#250) 2021-09-21 10:27:34 +05:30
README.md Use flatten function and modify ResultEvent in schema. (#247) 2021-09-17 17:10:08 +05:30
tsconfig.json Use flatten function and modify ResultEvent in schema. (#247) 2021-09-17 17:10:08 +05:30

Code Generator

Setup

  • Run the following command to install required packages:

    yarn
    

Run

  • Run the following command to generate schema from a contract file:

    yarn codegen:gql --input-file <input-file-path> --output-file [output-file-path] --mode [eth_call | storage] --flatten [true | false]
    
    • input-file(alias: i): Input contract file path or an URL (required).
    • output-file(alias: o): Schema output file path (logs output using stdout if not provided).
    • mode(alias: m): Code generation mode (default: storage).
    • flatten(alias: f): Flatten the input contract file (default: true).

    Note: When passed an URL as input-file, it is assumed that it points to an already flattened contract file.

    Examples:

    yarn codegen:gql --input-file ./test/examples/contracts/ERC20.sol --output-file ./ERC20-schema.gql --mode eth_call
    
    yarn codegen:gql --input-file https://git.io/Jupci --output-file ./ERC721-schema.gql --mode storage
    

Demo

  • Install required packages:

    yarn
    
  • Generate schema from a contract file:

    yarn codegen:gql --input-file ../../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol --output-file ./ERC20-schema.gql --mode storage
    
  • Generate schema from a flattened contract file from an URL:

    yarn codegen:gql --input-file https://git.io/Jupci --output-file ./ERC721-schema.gql --mode eth_call
    

References

Known Issues

  • Currently, node-fetch v2.6.2 is being used to fetch from URLs as v3.0.0 is an ESM-only module and ts-node transpiles to import it using require.