watcher-ts/packages/codegen/README.md
Ashwin Phatak 6560639a68
Use flatten function and modify ResultEvent in schema. (#247)
Co-authored-by: prathamesh <prathamesh.musale0@gmail.com>
2021-09-17 17:10:08 +05:30

2.0 KiB

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.