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

How to get the gas fee when transfer ton or jetton token #281

Open
0xryanz opened this issue Nov 19, 2024 · 9 comments
Open

How to get the gas fee when transfer ton or jetton token #281

0xryanz opened this issue Nov 19, 2024 · 9 comments

Comments

@0xryanz
Copy link

0xryanz commented Nov 19, 2024

How to get the estimate gas fee when transfer ton or jetton token ?

@wythers
Copy link

wythers commented Nov 19, 2024

Sorry bro, theoretically, you can’t know the exact fee before the transaction is confirmed.

Fees on TON are difficult to calculate in advance, as their amount depends on transaction run time, account status, message content and size, blockchain network settings, and a number of other variables that cannot be calculated until the transaction is sent.

but there is a workaround method to estimate the fee from the history of similar transactions. Some third-party APIs provide such methods, for example:
toncenter estimate fee API.

And, when your transaction was confirmed, you can use the return of SendWaitTransaction with TotalFeesmethod to obtain the exact fee:

      tx, _, err := w.SendWaitTransaction(ctx, msg)
      fmt.Println("fee:", tx.TotalFees.Coins.String())

@0xryanz
Copy link
Author

0xryanz commented Nov 20, 2024

thanks

@aitimate
Copy link

Sorry bro, theoretically, you can’t know the exact fee before the transaction is confirmed.

Fees on TON are difficult to calculate in advance, as their amount depends on transaction run time, account status, message content and size, blockchain network settings, and a number of other variables that cannot be calculated until the transaction is sent.

but there is a workaround method to estimate the fee from the history of similar transactions. Some third-party APIs provide such methods, for example: toncenter estimate fee API.

And, when your transaction was confirmed, you can use the return of SendWaitTransaction with TotalFeesmethod to obtain the exact fee:

      tx, _, err := w.SendWaitTransaction(ctx, msg)
      fmt.Println("fee:", tx.TotalFees.Coins.String())

HI, can you help me pls. I need a example, I tried a lot but failed:

body := cell.BeginCell().
		MustStoreUInt(0xf8a7ea5, 32).                                      // method ID
		MustStoreUInt(uint64(rand.Int63()), 64).                           // queryId
		MustStoreCoins(ethx.Uint64(amount.Nano())).                        // amount
		MustStoreAddr(to).                                                 // destination
		MustStoreAddr(tokenWallet.Address()).                              // responseDestination
		MustStoreMaybeRef(comment).                                        // customPayload
		MustStoreCoins(ethx.Uint64(tlb.MustFromTON("0.05").Nano())).       // forwardTonAmount
		MustStoreSlice(forwardPayload.ToBOC(), forwardPayload.BitsSize()). // forwardPayload
		EndCell()
	feeInfo, _, err := consts.ClientTon.ApiIterator.Next().Apiv2Api.ApiV3PostV2EstimateFee(context.Background(), toncenter.V2EstimateFeeRequest{
		Address:      usdt.String(),
		Body:         base64.StdEncoding.EncodeToString(body.ToBOC()),
		IgnoreChksig: true,
	})

responst: {"source_fees":{"in_fwd_fee":494400,"storage_fee":594}}

Although there are no errors, I believe the returned information must be incorrect because its value is approximately 10 times different from the actual value.

@aitimate
Copy link

thanks

hi bro, do you solved it?

@wythers
Copy link

wythers commented Nov 22, 2024

fwd fee plus storage fee = total 0.000494994 TON, seems to be no problem.

thanks

hi bro, do you solved it?

Em, fwd fee plus storage fee = total 0.000494994 TON, seems to be no problem.

@aitimate
Copy link

thanks

hi bro, do you solved it?

It estimates the fee for the entire jetton line, not the fee for your wallet to your jetton wallet

And the entire jetton line fee includes jetton transfer, jetton internal transfer, notify msg, and excess msg. So, Total 0.000494994 TON, seems to be no problem.

no, see: https://tonviewer.com/transaction/cf1fcebfa405fc117affd8ab040cb3a9550d55d97f232ca49760cd82fca9047c?section=valueFlow

The values differ by an order of magnitude of 10.

@wythers
Copy link

wythers commented Nov 22, 2024

thanks

hi bro, do you solved it?

It estimates the fee for the entire jetton line, not the fee for your wallet to your jetton wallet

And the entire jetton line fee includes jetton transfer, jetton internal transfer, notify msg, and excess msg. So, Total 0.000494994 TON, seems to be no problem.

no, see: https://tonviewer.com/transaction/cf1fcebfa405fc117affd8ab040cb3a9550d55d97f232ca49760cd82fca9047c?section=valueFlow

The values differ by an order of magnitude of 10.

Bro, the estimate API is ONLY for normal transaction, The way you transfer jettons is not normal. The API takes the records of previous normal transactions to match similar transactions

@aitimate
Copy link

thanks

hi bro, do you solved it?

It estimates the fee for the entire jetton line, not the fee for your wallet to your jetton wallet

And the entire jetton line fee includes jetton transfer, jetton internal transfer, notify msg, and excess msg. So, Total 0.000494994 TON, seems to be no problem.

no, see: https://tonviewer.com/transaction/cf1fcebfa405fc117affd8ab040cb3a9550d55d97f232ca49760cd82fca9047c?section=valueFlow
The values differ by an order of magnitude of 10.

Bro, the estimate API is ONLY for normal transaction, The way you transfer jettons is not normal. The API takes the records of previous normal transactions to match similar transactions

ohw, I see tonweb.ts is surpported

@wythers
Copy link

wythers commented Nov 22, 2024

thanks

hi bro, do you solved it?

It estimates the fee for the entire jetton line, not the fee for your wallet to your jetton wallet

And the entire jetton line fee includes jetton transfer, jetton internal transfer, notify msg, and excess msg. So, Total 0.000494994 TON, seems to be no problem.

no, see: https://tonviewer.com/transaction/cf1fcebfa405fc117affd8ab040cb3a9550d55d97f232ca49760cd82fca9047c?section=valueFlow
The values differ by an order of magnitude of 10.

Bro, the estimate API is ONLY for normal transaction, The way you transfer jettons is not normal. The API takes the records of previous normal transactions to match similar transactions

ohw, I see tonweb.ts is surpported

Nice, Typescript Ton ecosystem is much better than golang. hahahahhhhh

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

3 participants