Yes, it is possible to change the contract code in TON. Just implement it inside your smart contract that will be updating contract's code using FunC Standard Library (stdlib.fc) function:
() set_code(cell new_code) impure asm "SETCODE";
Simple implementation inside recv_internal
:
#include "stdlib.fc";
global slice ctx_owner;
() recv_internal(int my_balance, int msg_value, cell in_msg_full, slice in_msg_body) impure {
slice cs = in_msg_full.begin_parse();
int flags = cs~load_uint(4);
if (flags & 1) { ;; ignore all bounced messages
return ();
}
;; Admin methods
;; if the in_msg_body is empty, then it is a simple money transfer
if (equal_slice_bits(sender_addr, ctx_owner) & (~ in_msg_body.slice_empty?())) {
int op = in_msg_body~load_uint(32);
if (op == "op::update_code"c) {
set_code(in_msg_body~load_ref());
}
}
}
Also, you can find specification of set_code
here: https://ton.org/docs/develop/func/stdlib/#set_code