Generate Go code for your CosmWasm smart contracts.
go install github.com/srdtrk/go-codegen@latest
The quickest way to generate Go code for your CosmWasm smart contracts. Currently, this tool supports generating:
- Message types
- A gRPC query client
- An
interchaintestbased test suite
You can find a tutorial on how to use this tool's interchaintest feature here.
In order to generate Go code for your CosmWasm smart contract, you need to have its full API exported as a JSON file
using cosmwasm-schema.
Once you have the JSON file, you can use it to generate the Go code.
Note that you can learn more about how to use this tool by running go-codegen help or -h flag with any command.
go-codegen generate messages /path/to/contract-api.json --output /path/to/output.go --package-name mypackageThis will generate the Go code in the specified optional output directory, if not specified, it will generate the code in msgs.go in the current directory.
Package name is also optional, if not specified, it will use the name of the contract.
go-codegen generate query-client /path/to/contract-api.json -o /path/to/output.go -p mypackageThis will generate the Go code in the specified optional output directory, if not specified, it will generate the code in query.go in the current directory. Package name is also optional, if not specified, it will use the name of the contract. The generated code depends on the generated messages, the wasmd package, and the grpc package. You can install them by running go get github.com/CosmWasm/wasmd@latest (or go get github.com/CosmWasm/[email protected] for a specific version) and go get google.golang.org/grpc@latest (or go get google.golang.org/[email protected] for a specific version).
go-codegen interchaintest scaffoldThis will launch an interactive prompt to guide you through the process of generating the test suite.
The scaffolded test suite will include a basic test and instructions on how to run it. This test suite will not contain any contract specific code, or tests, you will need to add them using add-contract command.
go-codegen interchaintest add-contract /path/to/contract-api.json --suite-dir /path/to/suiteThis will add a contract to the test suite. The suite directory is the directory where the test suite is located. If not specified, it will use the current directory. The contract API JSON file is the same file that was used to generate the messages and query client.
Note that you can find a tutorial on how to use this tool's interchaintest feature here.
The Go Gopher mascot was created by Renee French and is licensed under the Creative Commons 4.0 Attribution License.
I've modified the original image to include the logo of ts-codegen.