[BUG] calculateFee calculates wrongly
Closed this issue · 1 comments
SeiJS package & version
@sei-js/cosmjs: 1.0.5
@sei-js/proto: 4.0.5
@cosmjs/stargate: 0.32.3
Chain ID
testnet
Describe the bug
While running calculate fee like this while trying to get max value to send
const fee = calculateFee(balance, "0.1usei");
It calculates amount for example 4500 usei, balance was 45000usei
then I am sending it, after substracting 45000 usei from balance and sendAmount there is 40500 usei
then i calculate fee once again with balance = 40500 in sendAmount
const send = await signingClient.sendTokens(
activeAccount.address,
receiver,
[sendAmount],
fee,
);
but after this I got this error Log: out of gas in location: ReadPerByte; gasWanted: 45000, gasUsed: 45019: out of gas]
To Reproduce
Described up
Expected behavior
Calculate correct amount of fee and let me send transaction
The first param in calculateFee
is actually gas limit, not the amount. Amount isn't used to calculate the fee needed for the transaction. You just need gas limit and price and it's calculated like this: gas limit * gas price
.
In your case, you're passing in a gas limit of 45000
and a gas price of 0.1usei
resulting in a gas cost of 4500usei
. The error log is because the amount of gas required for a bank send is ~90k, so you will need to pass in a gas limit higher than that.