hyperweb-io / hyperweb-io/cosmos-kit
Default gas/gasPrice function for SignerOptions
- Dominant language
- TypeScript
- Stars
- 201
- Forks
- 159
- PR merge metrics
- No merged PRs in 30d
Description
I've seen many cases where people fail or have to explicitly configure gas for each chain signer.
Here is the spot im referring to: [SignerOptions](https://github.com/cosmology-tech/cosmos-kit/blob/main/packages/core/types/types/manager.d.ts#L9-L10)
Example where you must specify:
https://github.com/cosmology-tech/create-cosmos-app/blob/main/examples/stargaze/pages/_app.tsx#L18-L30
Here's a proposed solution that utilizes the chains known/published config instead as the default. Saving dev brain cycles:
```js
const defaultGasForChain = (chain: Chain) => {
let gasPrice: any = `0.04${chain.bech32_prefix}`
if (chain?.fees && chain?.fees.fee_tokens) {
const fee = chain?.fees.fee_tokens[0]
const feeDenom = `${fee.denom}`.search('ibc/') === -1 ? `u${fee.denom.replace('u', '')}` : 'token'
const feeUnit = `${fee.average_gas_price || fee.low_gas_price || fee.fixed_min_gas_price || 0}${feeDenom}`
try {
gasPrice = GasPrice.fromString(feeUnit)
} catch (e) {
console.error(e)
}
}
return { gasPrice };
}
# use:
const signerOptions: SignerOptions = {
signingStargate: defaultGasForChain,
signingCosmwasm: defaultGasForChain,
};
```
As you can see, makes things MUCH simpler. I would do a PR but im not finding where the exact right spot is for this! :/
Thoughts @liujun93 @pyramation ??
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.