Skip to content

Commit

Permalink
add fees flag to node tx bank send cmd
Browse files Browse the repository at this point in the history
fees are required, at least in cosmos-hub to send funds to an other
account. W/o fees the transaction returns this message:
error code: '13' msg: 'insufficient fees; got:  required: 8uatom:
insufficient fee'
  • Loading branch information
tbruyelle committed Jul 29, 2022
1 parent 0ab22ac commit 009538f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ignite/cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func newNodeCosmosClient(cmd *cobra.Command) (cosmosclient.Client, error) {
keyringDir = getKeyringDir(cmd)
gas = getGas(cmd)
gasPrices = getGasPrices(cmd)
fees = getFees(cmd)
)

options := []cosmosclient.Option{
Expand All @@ -52,6 +53,9 @@ func newNodeCosmosClient(cmd *cobra.Command) (cosmosclient.Client, error) {
if gasPrices != "" {
options = append(options, cosmosclient.WithGasPrices(gasPrices))
}
if fees != "" {
options = append(options, cosmosclient.WithFees(fees))
}

return cosmosclient.New(cmd.Context(), options...)
}
Expand Down
6 changes: 6 additions & 0 deletions ignite/cmd/node_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
gasFlagAuto = "auto"
flagGasPrices = "gas-prices"
flagGas = "gas"
flagFees = "fees"
)

func NewNodeTx() *cobra.Command {
Expand Down Expand Up @@ -59,3 +60,8 @@ func getGas(cmd *cobra.Command) string {
gas, _ := cmd.Flags().GetString(flagGas)
return gas
}

func getFees(cmd *cobra.Command) string {
fees, _ := cmd.Flags().GetString(flagFees)
return fees
}
1 change: 1 addition & 0 deletions ignite/cmd/node_tx_bank_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func NewNodeTxBankSend() *cobra.Command {
c.Flags().AddFlagSet(flagSetKeyringDir())
c.Flags().AddFlagSet(flagSetGenerateOnly())
c.Flags().AddFlagSet(flagSetGasFlags())
c.Flags().String(flagFees, "", "Fees to pay along with transaction; eg: 10uatom")

return c
}
Expand Down
13 changes: 11 additions & 2 deletions ignite/pkg/cosmosclient/cosmosclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type Client struct {

gas string
gasPrices string
fees string
}

// Option configures your client.
Expand Down Expand Up @@ -164,6 +165,13 @@ func WithGasPrices(gasPrices string) Option {
}
}

// WithFees sets the fees (e.g. 10uatom)
func WithFees(fees string) Option {
return func(c *Client) {
c.fees = fees
}
}

// New creates a new client with given options.
func New(ctx context.Context, options ...Option) (Client, error) {
c := Client{
Expand Down Expand Up @@ -337,10 +345,11 @@ func (c Client) CreateTx(account cosmosaccount.Account, msgs ...sdktypes.Msg) (T
return TxService{}, err
}
// the simulated gas can vary from the actual gas needed for a real transaction
// we add an additional amount to endure sufficient gas is provided
gas += 10000
// we add an additional amount to ensure sufficient gas is provided
gas += 20000
}
txf = txf.WithGas(gas)
txf = txf.WithFees(c.fees)

if c.gasPrices != "" {
txf = txf.WithGasPrices(c.gasPrices)
Expand Down

0 comments on commit 009538f

Please sign in to comment.