Hello World
This is the most basic lua smart contract to store and retrieve states in Meey. You can save a name on the blockchain with the contract call function. And you can print ‘hello …’ with the query function.
-- Define global state variables
state.var {
Name = state.value(),
My_map = state.map()
}
-- Initialize the state variables
function constructor()
-- a constructor is called only once at the contract deployment
Name:set("world")
My_map["key"] = "value"
end
-- Update the name
-- @call
-- @param name string: new name
function set_name(name)
Name:set(name)
end
-- Say hello
-- @query
-- @return string: 'hello ' + name
function hello()
return "hello " .. Name:get()
end
-- register functions to expose
abi.register(set_name, hello)This is explained based on using cli. Variables used in this example are
Account to deploy and execute a contract: AmPPCH5aMeHnaBPJ782UynpdFa612d8runz2zY83P4AcPHqTrhqL
Cli commands in this page need a meeysvr with enable personal feature
Check Account and Balance
First, you need an account with enough balance to deploy and execute smart contracts. (If you don’t) Import or Unlock Account to meey server.
Compile Contract
Copy above code and save it to a file (e.g. helloword.lua). And Compile using the meeyluac compiler
Get receipt of contract
Look up the actual contract address with the transaction ID above.
If the status is not ‘CREATED’, it may not be included in the block yet, or there may be an error. Wait a while until the transaction is included in the block. Or check the server’s error log.
Get ABI of contract
Look up ABI of contract with the contract address above.
Query Initial State
You can query the generated contract in the following way.
You can see that the name ‘world’ assigned by the constructor is output.
Call Contract
You can change the name recorded in the block chain as follows:
Query Changed State
If you look at the results again, it has changed.
Query contract variable with merkle proof
Value
Map
Array
By default, the returned state is the one at the latest block, but you may specify any past block’s state root.
Last updated