Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to accurately calculate the transfer fee? #23

Open
mahnunchik opened this issue Feb 13, 2024 · 3 comments
Open

[Question] How to accurately calculate the transfer fee? #23

mahnunchik opened this issue Feb 13, 2024 · 3 comments

Comments

@mahnunchik
Copy link

Hello, I've faced with the issue that estimated fee doesn't math the real fee paid for the transfer.

import { WalletContractV4, TonClient, internal } from '@ton/ton';

const client = new TonClient({
  endpoint: 'https://testnet.toncenter.com/api/v2/jsonRPC',
});

const wallet = WalletContractV4.create({
  publicKey: key.publicKey,
  workchain: 0,
});

const walletContract = client.open(wallet);
const seqno = await walletContract.getSeqno();

const transfer = await walletContract.createTransfer({
  secretKey: key.secretKey,
  seqno: seqno,
  messages: [
    internal({
      to: secondAddress,
      value: sendAmount,
      body: "Hello",
      bounce: false,
    })
  ],
});

console.log('estimate:', await client.estimateExternalMessageFee(wallet.address, { body: transfer } ));

await walletContract.send(transfer);

Estimation output

{
  '@type': 'query.fees',
  source_fees: {
    '@type': 'fees',
    in_fwd_fee: 1564000,
    storage_fee: 108763,
    gas_fee: 3308000,
    fwd_fee: 1000000
  }
}

Sum of storage_fee + in_fwd_fee + fwd_fee + gas_fee equals 5980763 which is 3 gram less then real fee paid for the transaction https://testnet.tonscan.org/tx/2xRWxV-7sIxMWpT8xmLGYgc5Z8YOk93GZVURJzw2Ro0= (0,005980766 TON = 5980766).

Fee estimation shortage may differ from 2 to 100 grams, but always less then real fee.

How to accurately calculate the transfer fee?

@mahnunchik
Copy link
Author

Related issue: toncenter/tonweb#124

@mahnunchik
Copy link
Author

@dvlkv any ideas?

@dvlkv
Copy link
Collaborator

dvlkv commented Feb 26, 2024

Hi! Have you tried to use computeExternalMessageFees, computeFwdFees, computeGasPrices, computeMessageForwardFees, computeStorageFees provided by library? You can find examples here: fees.spec.ts

aSpite pushed a commit to aSpite/ton that referenced this issue Jun 11, 2024
* wip: adding fees computation utils

* wip: adding fees test

* wip: adding test comparisons

* wip: adding test comparisons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants