Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
Is it possible to change a deployed smart contract on TON?

Blockchains are considered "append-only" and immutable. But I've heard that in the TON world smart contracts can change their own code. So, is it possible for a contract code to be changed after it was deployed and how does that work?


This question was imported from Telegram Chat: https://t.me/tondev/84920

Votes Newest

Answers


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

18K Views
1 Answer
one year ago
one year ago
Tags