trustwallet / wallet-core

Cross-platform, cross-blockchain wallet library.

Home Page:https://developer.trustwallet.com/wallet-core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[TON] Calculating Transaction Network Fees

ronaldoguedess opened this issue · comments

I'm implementing TON (The Open Network) and using Trust Wallet Core to build TON transactions. However, I noticed that the network fee calculation is missing in the sample code.

Is there a way to get the network fee for TON transactions similar as we can calculate fees using .plan for Bitcoin?
AnySigner.sign(input, CoinType.TON, TheOpenNetwork.SigningOutput.parser())

Hi @ronaldoguedess

After you sign, you can get "encoded" from SigningOutput and call

/estimateFee from node

https://toncenter.com/api/v2/#/send/estimate_fee_estimateFee_post

Hi @JaimeToca

So, there is no off-chain soluction to calc this fee like we have in bitcoin?

I tested this api and it provide me it...
Can I considere just this field? "gas_fee": 155200, or should I considere the match of in_fwd_fee + storage_fee + gas_fee?

{
  "ok": true,
  "result": {
    "@type": "query.fees",
    "source_fees": {
      "@type": "fees",
      "in_fwd_fee": 926400,
      "storage_fee": 11819211,
      "gas_fee": 155200,
      "fwd_fee": 0
    },
    "destination_fees": [],
    "@extra": "1717772010.2004683:12:0.7120622247973473"
  }
}

Hi @JaimeToca

So, there is no off-chain soluction to calc this fee like we have in bitcoin?

I tested this api and it provide me it... Can I considere just this field? "gas_fee": 155200, or should I considere the match of in_fwd_fee + storage_fee + gas_fee?

{
  "ok": true,
  "result": {
    "@type": "query.fees",
    "source_fees": {
      "@type": "fees",
      "in_fwd_fee": 926400,
      "storage_fee": 11819211,
      "gas_fee": 155200,
      "fwd_fee": 0
    },
    "destination_fees": [],
    "@extra": "1717772010.2004683:12:0.7120622247973473"
  }
}

Fees = in_fwd_fee + storage_fee + gas_fee + fwd_fee

In BTC you still need the price from the network. Not I am not aware of.

Hey, is there something wrong with this?

I've successfully broadcasted my transaction, but the gas fee seems completely off.

Here's what the API shows me before and based on my transaction and wallet address:

image

{
  "ok": true,
  "result": {
    "@type": "query.fees",
    "source_fees": {
      "@type": "fees",
      "in_fwd_fee": 987200,
      "storage_fee": 137,
      "gas_fee": 0,
      "fwd_fee": 0
    },
    "destination_fees": [],
    "@extra": "1718588867.165973:1:0.445657813246111"
  }
}