diff --git a/cmd.go b/cmd.go index 52712ad..20a77c0 100644 --- a/cmd.go +++ b/cmd.go @@ -227,7 +227,7 @@ func CreateEVMCommand() *cobra.Command { func CreateEVMGenerateCommand() *cobra.Command { var cli, noformat, includemain bool - var infile, packageName, structName, bytecodefile, outfile, foundryBuildFile string + var infile, packageName, structName, bytecodefile, outfile, foundryBuildFile, hardhatBuildFile string var rawABI, bytecode []byte var readErr error var aliases map[string]string @@ -263,6 +263,22 @@ func CreateEVMGenerateCommand() *cobra.Command { readErr = json.Unmarshal(contents, &artifact) rawABI = []byte(artifact.ABI) bytecode = []byte(artifact.Bytecode.Object) + } else if hardhatBuildFile != "" { + var contents []byte + contents, readErr = os.ReadFile(hardhatBuildFile) + if readErr != nil { + return readErr + } + + type hardhatBuildArtifact struct { + ABI json.RawMessage `json:"abi"` + Bytecode string `json:"bytecode"` + } + + var artifact hardhatBuildArtifact + readErr = json.Unmarshal(contents, &artifact) + rawABI = []byte(artifact.ABI) + bytecode = []byte(artifact.Bytecode) } else if infile != "" { rawABI, readErr = os.ReadFile(infile) } else { @@ -316,8 +332,9 @@ func CreateEVMGenerateCommand() *cobra.Command { evmGenerateCmd.Flags().BoolVar(&noformat, "noformat", false, "Set this flag if you do not want the generated code to be formatted (useful to debug errors)") evmGenerateCmd.Flags().BoolVar(&includemain, "includemain", false, "Set this flag if you want to generate a \"main\" function to execute the CLI and make the generated code self-contained - this option is ignored if --cli is not set") evmGenerateCmd.Flags().StringVarP(&outfile, "output", "o", "", "Path to output file (default stdout)") - evmGenerateCmd.Flags().StringVar(&foundryBuildFile, "foundry", "", "If your contract is compiled using Foundry, you can specify a path to the build file here (typically \"/out//.json\") instead of specifying --abi and --bytecode separately") - evmGenerateCmd.Flags().StringToStringVar(&aliases, "alias", nil, "A map of identifier aliaes (e.g. --alias name=somename)") + evmGenerateCmd.Flags().StringVar(&foundryBuildFile, "foundry", "", "If your contract is compiled using Foundry, you can specify a path to the build file here (typically \"/out//.json\") instead of specifying --abi and --bytecode separately") + evmGenerateCmd.Flags().StringVar(&hardhatBuildFile, "hardhat", "", "If your contract is compiled using Hardhat, you can specify a path to the build file here (typically \"/.json\") instead of specifying --abi and --bytecode separately") + evmGenerateCmd.Flags().StringToStringVar(&aliases, "alias", nil, "A map of identifier aliases (e.g. --alias name=somename)") return evmGenerateCmd } diff --git a/version/version.go b/version/version.go index bbe96c6..6e24004 100644 --- a/version/version.go +++ b/version/version.go @@ -1,3 +1,3 @@ package version -var SeerVersion string = "0.1.2" +var SeerVersion string = "0.1.3"