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

Proposal to include information about the gas fee #1

Closed
cryshado opened this issue Jan 14, 2022 · 4 comments
Closed

Proposal to include information about the gas fee #1

cryshado opened this issue Jan 14, 2022 · 4 comments

Comments

@cryshado
Copy link
Contributor

A lot of users ask how gas fees are charged in TON smart contracts.
That's why I propose to include information about it in this repository.

Logical inference:

There is no point in calling accept_message() within the internal message, since the gas fees come with the TONs that came with the transaction.

(Suggestion: if accept_message() in internal, it will allow to use the balance of the contract)

Within external message, the payment for gas only goes for transactions that change something in the blockchain(the rest is free). It need to call accept_message() after "all checks", before changing something in blockchain(like contract storage or for example send_raw_message())

  • please experienced people to correct me if i wrote something wrong
@akifoq
Copy link

akifoq commented Jan 14, 2022

accept_message simply sets the gas limit to the maximal possible value (the gas that can be bought by both original contract balance and message value, or, more commonly, the maximal gas amount allowed to use in single transaction) and also sets gas credit to zero.

In the case of external messages you need to accept the message in order to make transaction appear in the block (or, more precisely speaking, you need to somehow set gas credit to zero). You can accept message at any time during the TVM execution, even after calling send_raw_message primitive. The only way the fees may be charged from the account is to put a transaction into the blockchain, so it's the reason why "transactions" with no accept_message are "free".

In the case of internal messages the initial gas limit is set equal to the amount of gas that can be bought by message value. accept_message raises that limit. Even without accept_message you can spend more coins than the message value by sending some other messages which carry value.

@cryshado
Copy link
Contributor Author

cryshado commented Jan 14, 2022

@akifoq Then perhaps a good practice for internal messages would be to use set_gas_limit to limit the charge for gas within the TON amount sent with the message. is it true? Or it still doesn't help to limit gas in the case of sending other messages that carry value?

@akifoq
Copy link

akifoq commented Jan 14, 2022

It doesn't help and the gas limit is by default set in such way. Gas fees are the fees on computation only. You can use small amount of gas, but send a message with large amount of coins. You can use raw_reserve in addition to gas limit to limit spendable amount of coins.

@cryshado
Copy link
Contributor Author

@akifoq thanks for the detailed answer!

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