basics transaction code - SkycoinWikis/CXChains GitHub Wiki

CXCHAINS HOME » CX » CX CHAINS » TRANSACTION CODE

Transaction Code

The program state that is stored on the blockchain can either be mutated or queried by running a program that "imports" the program state. Actually, in order to have any sort of access to the program state, a program needs to import packages that are stored in the program state. As a minimalist example, consider the following code:

package number

var Num i32

func main() {
	Num = 10
}

In order to modify the value of Num, the following transaction code can be used:

package main
import "number"

func main() {
	number.Num = 11
}

As can be seen, this resembles exactly what would happen in a CX program that is importing a package, either located in the same file or in an external file. The difference between a CX chain and the aforementioned situation is that in a CX chain, the program state will be preserved. For example, consider the following transaction code:

package main
import "number"

func main() {
	i32.print(number.Num)
}

In the case above, i32.print(number.Num) will print 11, because the previous transaction code modified the value of number.Num.

NEXT ->