cosmjs: Unable to perform `MsgExec` authz transaction in CosmJS

We are building a frontend where the facility of paying gas fee for someone else is being implemented. To do this, we are using the x/authz and x/feegrant module to do the job.

While we could run the /cosmos.authz.v1beta1.MsgGrant and /cosmos.feegrant.v1beta1.MsgGrantAllowance in CosmJS, we were not able to do cosmos.authz.v1beta1.MsgExec transaction, as it gave the error 0uhid is smaller than 100uhid: insufficient funds: insufficient funds.

This is the overall setup of the code for executing MsgExec Tx:

async function execTx() {
  const grantee_mnemonic = " ----- grantee's mnemonic ------"
  const wallet =  await DirectSecp256k1HdWallet.fromMnemonic(grantee_mnemonic, options = { prefix: "hid" })
  
  const client = SigningStargateClient.connectWithSigner(
    "http://localhost:26657",
     wallet,
    { 
        registry: // Custom Module TypeURLs are added ,
        gasPrice: GasPrice.fromString("0.0001uhid"),
    },
  )
  
  let grantee = "hid1k77resf8gktl5wh8fhwlqt7pccandeyj9z5702"  // account with no money
  let customTypeUrl = "/hypersignprotocol.hidnode.ssi.MsgCreateDID"
  
  // The Custom Module Message that the grantee needs to execute
  const txCreateDIDMessage = {
  typeUrl: customTypeUrl,
  value: MsgCreateDID.encode(
      MsgCreateDID.fromPartial({
          didDocString: "---",
          signatures: "---",
          creator: "---",
      })).finish(),
  };
  
  // MsgExec Tx Object
  const txAuthMessage = {
    typeUrl: "/cosmos.authz.v1beta1.MsgExec",
    value: {
        grantee: grantee,
        msgs: [
            txCreateDIDMessage
        ]
    },
  };
  
  const txResult = await client.signAndBroadcast(grantee, [txAuthMessage], "auto");
  return txResult
}

CLI execution (hid-noded tx authz exec tx.json --from <grantee-address> --fee-account <granter's-address> --fees 90uhid) worked fine, but we are struggling with CosmJs execution.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

Yeah, this can happen when VSCode’s TypeScript server does not find the type definitions of other packages in the same repo because they are not built yet. Running yarn build in the repo root and restarting the IDE should help.

What about this: only allow setting the fee payer when the fee is set explicitly (via StdFee)? Once this is available we can think about making “auto” fee and fee payer work together.

Based on my exploration, it is clear that for MsgExec to work, the granter field of AuthInfo in Tx needs to be populated with the address who will pay for the fees.

The fee argument of signAndBroadcast() accepts value of type StdFee, which comprises of two attributes namely amount and gas. When signAndBroadcast() executes, the fee value is passed down, to finally reach to makeAuthInfoBytes(), which composes AuthInfo. Hence, it is intuitive to think about adding an optional field, say feePayer, in StdFee interface, which can be assigned in the granter field of AuthInfo.

However, signAndBroadcast() also accepts “auto” and Number type as well, which leaves no scope to pass the fee payer’s address.

My suggestion is to code a method similar to sendTokens(), specifically meant to perform the MsgExec transaction. It will include feePayer and fee as the input parameters, making it easier to pass feePayer to AuthInfo.

@webmaster128 What are you thoughts on this approach?

Sure, will do

Amazing! Have a look at HACKING.md for how to start developing CosmJS.

CosmJS does not yet have a way to set the fee payer for the feegrant module. This is tracked as part of https://github.com/cosmos/cosmjs/issues/1105. So it seems like the message signer (grantee) is supposed to pay the fee and this account has a 0 balance (“0uhid is smaller than 100uhid”).

Would you be interested in working on that feature for CosmJS? I’m happy to help in that case.