Lua Contract Language
MagnaChain’s smart contract is written in Lua and is modified from the official 5.1 version. Most of the syntax is reserved. The number type is changed to long long; no other data types have been modified. We also removed security-related basic libraries (e.g. io, os, etc.) and floating-point related operation functions. We retained math.pow, math.max, math, and min.
Contract Interface Visibility
Global functions are available for external calls, and local functions can only be called internally in contracts.
Data Persistence and Initialization
The data that needs to be stored in the contract is added to the global variable PersistentData.
Cost of the Contract
Publishing and invoking contracts require a small fee. The fee is calculated based on the number of instructions executed and the size of the data that needs to be stored.
Caller and block related data
In the contract can get the following data through the global table msg：
|sender||string||contract’s calling address|
|payment||number||magna sending contract|
|timestamp||number||block time when entering the block|
|blocknumber||number||block height when entering the block|
Writing Smart Contracts
The contract is written using the Lua language script UTF8 (NOBOM) encoding format.
Users can add the data that needs to be saved to the global variable PersistentData. The data will be packaged and stored. The data size is limited to prevent excessive use of computer resources.
Users can choose whether or not to add the initialization interface init() according to their needs. The interface will be called once only when the contract is released and the corresponding fee will be calculated.