diff --git a/evm/generators.go b/evm/generators.go index e211c55..6cc36cd 100644 --- a/evm/generators.go +++ b/evm/generators.go @@ -1320,12 +1320,15 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command { Use: "deploy", Short: "Deploy a new {{.StructName}} contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if !calldata { + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } + + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -1395,6 +1398,22 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + // Generate deploy bytecode with constructor arguments + deployCalldata, err := generate{{.StructName}}DeployBytecode( + {{- range .DeployHandler.MethodArgs}} + {{.CLIVar}}, + {{- end}} + ) + if err != nil { + return fmt.Errorf("failed to generate deploy bytecode: %v", err) + } + + if calldata { + deployCalldataHex := hex.EncodeToString(deployCalldata) + cmd.Printf(deployCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -1419,22 +1438,6 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command { SetTransactionParametersFromArgs(transactionOpts, nonce, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, gasLimit, simulate) - // Generate deploy bytecode with constructor arguments - deployCalldata, err := generate{{.StructName}}DeployBytecode( - {{- range .DeployHandler.MethodArgs}} - {{.CLIVar}}, - {{- end}} - ) - if err != nil { - return fmt.Errorf("failed to generate deploy bytecode: %v", err) - } - - if calldata { - deployCalldataHex := hex.EncodeToString(deployCalldata) - cmd.Printf(deployCalldataHex) - return nil - } - if safeAddress != "" { // Create Safe proposal for deployment value := transactionOpts.Value @@ -1673,19 +1676,21 @@ func {{.HandlerName}}() *cobra.Command { Use: "{{(KebabCase .MethodName)}}", Short: "Execute the {{.MethodName}} method on a {{$structName}} contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -1729,6 +1734,34 @@ func {{.HandlerName}}() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := {{$structName}}MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "{{ToLowerCamel .MethodName}}" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + {{- range .MethodArgs}} + {{.CLIVar}}, + {{- end}} + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -1763,34 +1796,6 @@ func {{.HandlerName}}() *cobra.Command { TransactOpts: *transactionOpts, } - abi, err := {{$structName}}MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "{{ToLowerCamel .MethodName}}" - if safeFunction != "" { - methodName = safeFunction - } - - txCalldata, err := abi.Pack( - methodName, - {{- range .MethodArgs}} - {{.CLIVar}}, - {{- end}} - ) - - if err != nil { - return err - } - - if calldata { - txCalldataHex := hex.EncodeToString(txCalldata) - cmd.Printf(txCalldataHex) - return nil - } - if safeAddress != "" { // Create Safe proposal for transaction value := transactionOpts.Value diff --git a/examples/ownable-erc-721/OwnableERC721.go b/examples/ownable-erc-721/OwnableERC721.go index 66c058b..2ea8bb5 100644 --- a/examples/ownable-erc-721/OwnableERC721.go +++ b/examples/ownable-erc-721/OwnableERC721.go @@ -1,5 +1,5 @@ // This file was generated by seer: https://github.com/G7DAO/seer. -// seer version: 0.3.13 +// seer version: 0.3.14 // seer command: seer evm generate --package main --cli --includemain --abi fixtures/OwnableERC721.json --bytecode fixtures/OwnableERC721.bin --struct OwnableERC721 --output examples/ownable-erc-721/OwnableERC721.go // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. @@ -1328,12 +1328,15 @@ func CreateOwnableERC721DeploymentCommand() *cobra.Command { Use: "deploy", Short: "Deploy a new OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if !calldata { + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } + + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -1406,6 +1409,22 @@ func CreateOwnableERC721DeploymentCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + // Generate deploy bytecode with constructor arguments + deployCalldata, err := generateOwnableERC721DeployBytecode( + name_0, + symbol, + owner, + ) + if err != nil { + return fmt.Errorf("failed to generate deploy bytecode: %v", err) + } + + if calldata { + deployCalldataHex := hex.EncodeToString(deployCalldata) + cmd.Printf(deployCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -1430,22 +1449,6 @@ func CreateOwnableERC721DeploymentCommand() *cobra.Command { SetTransactionParametersFromArgs(transactionOpts, nonce, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, gasLimit, simulate) - // Generate deploy bytecode with constructor arguments - deployCalldata, err := generateOwnableERC721DeployBytecode( - name_0, - symbol, - owner, - ) - if err != nil { - return fmt.Errorf("failed to generate deploy bytecode: %v", err) - } - - if calldata { - deployCalldataHex := hex.EncodeToString(deployCalldata) - cmd.Printf(deployCalldataHex) - return nil - } - if safeAddress != "" { // Create Safe proposal for deployment value := transactionOpts.Value @@ -2250,19 +2253,21 @@ func CreateApproveCommand() *cobra.Command { Use: "approve", Short: "Execute the Approve method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -2315,6 +2320,33 @@ func CreateApproveCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "approve" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + to0, + tokenId, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -2349,33 +2381,6 @@ func CreateApproveCommand() *cobra.Command { TransactOpts: *transactionOpts, } - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "approve" - if safeFunction != "" { - methodName = safeFunction - } - - txCalldata, err := abi.Pack( - methodName, - to0, - tokenId, - ) - - if err != nil { - return err - } - - if calldata { - txCalldataHex := hex.EncodeToString(txCalldata) - cmd.Printf(txCalldataHex) - return nil - } - if safeAddress != "" { // Create Safe proposal for transaction value := transactionOpts.Value @@ -2475,19 +2480,21 @@ func CreateMintCommand() *cobra.Command { Use: "mint", Short: "Execute the Mint method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -2540,6 +2547,33 @@ func CreateMintCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "mint" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + to0, + tokenId, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -2574,33 +2608,6 @@ func CreateMintCommand() *cobra.Command { TransactOpts: *transactionOpts, } - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "mint" - if safeFunction != "" { - methodName = safeFunction - } - - txCalldata, err := abi.Pack( - methodName, - to0, - tokenId, - ) - - if err != nil { - return err - } - - if calldata { - txCalldataHex := hex.EncodeToString(txCalldata) - cmd.Printf(txCalldataHex) - return nil - } - if safeAddress != "" { // Create Safe proposal for transaction value := transactionOpts.Value @@ -2695,19 +2702,21 @@ func CreateRenounceOwnershipCommand() *cobra.Command { Use: "renounce-ownership", Short: "Execute the RenounceOwnership method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -2747,6 +2756,31 @@ func CreateRenounceOwnershipCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "renounceOwnership" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -2781,31 +2815,6 @@ func CreateRenounceOwnershipCommand() *cobra.Command { TransactOpts: *transactionOpts, } - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "renounceOwnership" - if safeFunction != "" { - methodName = safeFunction - } - - txCalldata, err := abi.Pack( - methodName, - ) - - if err != nil { - return err - } - - if calldata { - txCalldataHex := hex.EncodeToString(txCalldata) - cmd.Printf(txCalldataHex) - return nil - } - if safeAddress != "" { // Create Safe proposal for transaction value := transactionOpts.Value @@ -2900,19 +2909,21 @@ func CreateSafeTransferFromCommand() *cobra.Command { Use: "safe-transfer-from", Short: "Execute the SafeTransferFrom method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -2972,49 +2983,15 @@ func CreateSafeTransferFromCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { - client, clientErr := NewClient(rpc) - if clientErr != nil { - return clientErr - } - - key, keyErr := KeyFromFile(keyfile, password) - if keyErr != nil { - return keyErr + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) } - chainIDCtx, cancelChainIDCtx := NewChainContext(timeout) - defer cancelChainIDCtx() - chainID, chainIDErr := client.ChainID(chainIDCtx) - if chainIDErr != nil { - return chainIDErr - } - - transactionOpts, transactionOptsErr := bind.NewKeyedTransactorWithChainID(key.PrivateKey, chainID) - if transactionOptsErr != nil { - return transactionOptsErr - } - - SetTransactionParametersFromArgs(transactionOpts, nonce, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, gasLimit, simulate) - - contract, contractErr := NewOwnableERC721(contractAddress, client) - if contractErr != nil { - return contractErr - } - - session := OwnableERC721TransactorSession{ - Contract: &contract.OwnableERC721Transactor, - TransactOpts: *transactionOpts, - } - - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "safeTransferFrom" - if safeFunction != "" { - methodName = safeFunction + // Generate transaction data (override method name if safe function is specified) + methodName := "safeTransferFrom" + if safeFunction != "" { + methodName = safeFunction } txCalldata, err := abi.Pack( @@ -3034,6 +3011,40 @@ func CreateSafeTransferFromCommand() *cobra.Command { return nil } + client, clientErr := NewClient(rpc) + if clientErr != nil { + return clientErr + } + + key, keyErr := KeyFromFile(keyfile, password) + if keyErr != nil { + return keyErr + } + + chainIDCtx, cancelChainIDCtx := NewChainContext(timeout) + defer cancelChainIDCtx() + chainID, chainIDErr := client.ChainID(chainIDCtx) + if chainIDErr != nil { + return chainIDErr + } + + transactionOpts, transactionOptsErr := bind.NewKeyedTransactorWithChainID(key.PrivateKey, chainID) + if transactionOptsErr != nil { + return transactionOptsErr + } + + SetTransactionParametersFromArgs(transactionOpts, nonce, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, gasLimit, simulate) + + contract, contractErr := NewOwnableERC721(contractAddress, client) + if contractErr != nil { + return contractErr + } + + session := OwnableERC721TransactorSession{ + Contract: &contract.OwnableERC721Transactor, + TransactOpts: *transactionOpts, + } + if safeAddress != "" { // Create Safe proposal for transaction value := transactionOpts.Value @@ -3139,19 +3150,21 @@ func CreateSafeTransferFrom0Command() *cobra.Command { Use: "safe-transfer-from-0", Short: "Execute the SafeTransferFrom0 method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -3221,6 +3234,35 @@ func CreateSafeTransferFrom0Command() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "safeTransferFrom0" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + from0, + to0, + tokenId, + data, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -3255,35 +3297,6 @@ func CreateSafeTransferFrom0Command() *cobra.Command { TransactOpts: *transactionOpts, } - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "safeTransferFrom0" - if safeFunction != "" { - methodName = safeFunction - } - - txCalldata, err := abi.Pack( - methodName, - from0, - to0, - tokenId, - data, - ) - - if err != nil { - return err - } - - if calldata { - txCalldataHex := hex.EncodeToString(txCalldata) - cmd.Printf(txCalldataHex) - return nil - } - if safeAddress != "" { // Create Safe proposal for transaction value := transactionOpts.Value @@ -3387,19 +3400,21 @@ func CreateSetApprovalForAllCommand() *cobra.Command { Use: "set-approval-for-all", Short: "Execute the SetApprovalForAll method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -3456,6 +3471,33 @@ func CreateSetApprovalForAllCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "setApprovalForAll" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + operator, + approved, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -3490,33 +3532,6 @@ func CreateSetApprovalForAllCommand() *cobra.Command { TransactOpts: *transactionOpts, } - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "setApprovalForAll" - if safeFunction != "" { - methodName = safeFunction - } - - txCalldata, err := abi.Pack( - methodName, - operator, - approved, - ) - - if err != nil { - return err - } - - if calldata { - txCalldataHex := hex.EncodeToString(txCalldata) - cmd.Printf(txCalldataHex) - return nil - } - if safeAddress != "" { // Create Safe proposal for transaction value := transactionOpts.Value @@ -3618,19 +3633,21 @@ func CreateTransferFromCommand() *cobra.Command { Use: "transfer-from", Short: "Execute the TransferFrom method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -3690,6 +3707,34 @@ func CreateTransferFromCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "transferFrom" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + from0, + to0, + tokenId, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -3724,34 +3769,6 @@ func CreateTransferFromCommand() *cobra.Command { TransactOpts: *transactionOpts, } - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "transferFrom" - if safeFunction != "" { - methodName = safeFunction - } - - txCalldata, err := abi.Pack( - methodName, - from0, - to0, - tokenId, - ) - - if err != nil { - return err - } - - if calldata { - txCalldataHex := hex.EncodeToString(txCalldata) - cmd.Printf(txCalldataHex) - return nil - } - if safeAddress != "" { // Create Safe proposal for transaction value := transactionOpts.Value @@ -3851,19 +3868,21 @@ func CreateTransferOwnershipCommand() *cobra.Command { Use: "transfer-ownership", Short: "Execute the TransferOwnership method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -3910,6 +3929,32 @@ func CreateTransferOwnershipCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "transferOwnership" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + newOwner, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -3944,32 +3989,6 @@ func CreateTransferOwnershipCommand() *cobra.Command { TransactOpts: *transactionOpts, } - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "transferOwnership" - if safeFunction != "" { - methodName = safeFunction - } - - txCalldata, err := abi.Pack( - methodName, - newOwner, - ) - - if err != nil { - return err - } - - if calldata { - txCalldataHex := hex.EncodeToString(txCalldata) - cmd.Printf(txCalldataHex) - return nil - } - if safeAddress != "" { // Create Safe proposal for transaction value := transactionOpts.Value