cosmos / cosmjs

The Swiss Army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers.
https://cosmos.github.io/cosmjs/
Apache License 2.0
645 stars 330 forks source link

SignAndBroadcast does not support fee granter #1458

Open dadamu opened 1 year ago

dadamu commented 1 year ago

Currently, to broadcast a transaction with a fee granter only can be implemented by manually signing tranasction because signAndBroadCast does not support feeGranter parameter.

const gasEstimation = await client!.simulate(creator, [msg], "");
const fee = calculateFee(Math.round(gasEstimation * 2), GasPrice.fromString("0.2udaric"));
const tx = await client!.signTx(creator, [msg], {
  fee,
  feeGranter: "fee granter address",
});
const txBytes = TxRaw.encode(tx.txRaw).finish();
const response = await client!.broadcastTx(txBytes, client!.broadcastTimeoutMs, client!.broadcastPollIntervalMs);

Providing feeGranter parameter to signAndBroadcast can make it simpler, like:

public async signAndBroadcast(
  signerAddress: string,
  messages: readonly EncodeObject[],
  fee: StdFee | "auto" | number,
  memo = "",
  feeGranter = "", // added
)