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)
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 buildin 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
MsgExecto work, the granter field of AuthInfo in Tx needs to be populated with the address who will pay for the fees.The
feeargument ofsignAndBroadcast()accepts value of typeStdFee, which comprises of two attributes namelyamountandgas. WhensignAndBroadcast()executes, the fee value is passed down, to finally reach tomakeAuthInfoBytes(), which composes AuthInfo. Hence, it is intuitive to think about adding an optional field, sayfeePayer, inStdFeeinterface, which can be assigned in thegranterfield of AuthInfo.However,
signAndBroadcast()also accepts “auto” andNumbertype 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 theMsgExectransaction. It will includefeePayerandfeeas the input parameters, making it easier to passfeePayerto 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.