Skip to content

Commit

Permalink
added fee calcualate
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwas1 committed Oct 7, 2024
1 parent b27708e commit a483cf8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/components/utils/cosmos-client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { SigningCosmWasmClient, CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import { Uint53 } from "@cosmjs/math";
import {
GasPrice, coins
} from "@cosmjs/stargate";
export async function createClient(rpcUrl, offlineSigner) {
const client = SigningCosmWasmClient.connectWithSigner(
rpcUrl,
Expand All @@ -12,3 +16,15 @@ export async function createNonSigningClient(rpcUrl) {
return client
}

export function calculateFee(gasLimit, gasPrice) {
const processedGasPrice = typeof gasPrice === "string" ? GasPrice.fromString(gasPrice) : gasPrice;
const { denom, amount: gasPriceAmount } = processedGasPrice;
// Note: Amount can exceed the safe integer range (https://github.com/cosmos/cosmjs/issues/1134),
// which we handle by converting from Decimal to string without going through number.
const t = gasPriceAmount.multiply(new Uint53(gasLimit))
const amount = t.toString();
return {
amount: coins(amount, denom),
gas: gasLimit.toString(),
};
}

0 comments on commit a483cf8

Please sign in to comment.