At the highest level, the smart contract is just a piece of state and code with defined functions and logic behind its selection. TON makes it even easier! It chose function selector depends on network event.
As soon as the account receives the message, it processes some actions. If the message is internal function selector is 0, if it is external function is -1.
Note: there are other cases when another continuation can be chosen. It will be discussed in future lessons.
The good knight FunC wraps this logic and lets you just write the code. The function for external messages (for example from you) should be named recv_external
and for internal (for example from other space objects) it should be recv_internal
.
Function's declaration has the following syntax:
([type, type, ...]) fun_name ([type arg_name, type arg_name, ...]) [modifier] {
;; function body
}
Then the simplest contract that accepts only external messages would be:
() recv_external(slice in_msg) impure {
;; function body
}
So recv_external
doesn't return any value but expects one argument in_msg
with type slice
. impure
says the function may modify contract storage. The brackets limits function block. ;;
is used for comments. recv_internal
has the same structure.
Your spaceship is going to process your external messages and do nothing but accept internal ones.
recv_external
and recv_internal
. Both functions have the same definition.<aside> 💡 Not visible for the user
</aside>
() recv_internal(slice in_msg) impure {
;; body
}
() recv_external(slice in_msg) impure {
;; body
}