github.com/mavryk-network/mvgo@v1.19.9/cmd/tzgen/README.md (about)

     1  # TzGen
     2  
     3  TzGen is a code generator that enables creating Golang struct types and smart contract interface bindings based on a contract's entrypoint specification. The generated code can be used to deploy, bootstrap, and call any chosen smart contract and interact with all of its entrypoints including views. The bindings read/decode data found in transaction parameters, transaction receipts (storage and bigmap updates), and contract storage as well as write/encode type-conform parameters for sending transactions.
     4  
     5  ## Installation
     6  
     7  ```bash
     8  go install github.com/mavryk-network/mvgo/cmd/tzgen
     9  ```
    10  
    11  ## Using TzGen
    12  
    13  When using TzGen you don't have to worry about details of Micheline or MvGo. TzGen produces all interfaces and types you'll need to call any of your contract's entrypoints, read its storage and bigmap entries.
    14  
    15  You can run tzgen manually which will write an auto-generated Go source file that you can build together with your project and check in to your repository.
    16  
    17  ### From a deployed contract
    18  
    19  ```bash
    20  tzgen -name <name> -pkg <pkg> -address <addr> -out <file.go>
    21  ```
    22  
    23  The endpoint is `https://rpc.tzstats.com` by default, but can be overridden with the `-endpoint` flag.
    24  
    25  ### From a Micheline file
    26  
    27  ```bash
    28  tzgen -name <name> -pkg <pkg> -src <file.json> -out <file.go>
    29  ```
    30  
    31  ### Go Generate
    32  
    33  You can also use tzgen in combination with the go generate tool if you want to create fresh interface definitions at build time. To use go generate you need to do two things:
    34  
    35  1. Add a go generate comment into a Go source code file:
    36  ```
    37  //go:generate go run -mod=mod github.com/mavryk-network/mvgo/cmd/tzgen -name <name> -pkg <pkg> -address <addr> -out <file.go>
    38  ```
    39  
    40  2. Call go generate `./path-to-your-pkg-or-cmd` to make Go call whatever script you have defined in 1:
    41  ```
    42  go generate ./cmd/myprog
    43  ```
    44  
    45  ## Renaming Structs
    46  
    47  Some structs don't have annotations in the contract's script.
    48  In this case, an auto-generated name is given.
    49  
    50  It is possible to give a configuration map to tzgen, to map these auto-generated names to the one you want.
    51  
    52  To do so, pass a yaml to tzgen with the `-fixup` flag.
    53  
    54  Example of a fixup file:
    55  
    56  ```yaml
    57  FA2NFTRecord3:
    58    name: OperatorForAll
    59    fields:
    60      Field0: Addr
    61      Field1: Owner
    62  
    63  FA2NFTRecord5:
    64    name: BalanceOfRequest
    65  
    66  FA2NFTRequest:
    67    equals: FA2NFTRecord5
    68  ```