5.1 Hello World!

As the first lesson to get started with any programming language, let's start with a detailed introduction to Hello World.

  1. Create a hello directory via command line or GUI tool
cd CONTRACTS_DIR
mkdir hello
cd hello
  1. Create a hello.lua file and open it with your favorite editor
touch hello.lua
  1. Add codes directly to hello.lua
function hello()
    chainhelper:log('Hello World!')
end
  1. Use the created test account (see here for details) to deploy the contract via cli_wallet
create_contract chandlerette contract.helloraven "COCOS8EgNn68Pydk3QatmPQc2mWJNYLP8w6ezszvfwEBygXxT5BKi4j" "function hello() chainhelper:log('Hello World!') end" true
  1. View the results of the contract deployment through the Terminal browser
  1. Call the hello interface via cli_wallet
call_contract_function chandlerette contract.helloraven hello [] true
  1. View transaction history via Terminal browser
  1. If you want to print the specific time, modify the codes as follows
function hello()
    chainhelper:log('Hello World!')
    chainhelper:log(date('%Y-%m-%dT%H:%M:%S', chainhelper:time()))
end
  1. Name the updated contract via cli_wallet
revise_contract chandlerette contract.helloraven "function hello() chainhelper:log('Hello World!') chainhelper:log(date('%Y-%m-%dT%H:%M:%S', chainhelper:time())) end" true
  1. View the transaction history of the updated contract through the Terminal browser
  1. Call the hello interface via cli_wallet
call_contract_function chandlerette contract.helloraven hello [] true
  1. View transaction history via Terminal browser

Conclusion

The development, deployment and update process of the basic contract is demoed with the example of Hello World, which is very simple. Due to the nature of the Lua language, the code of the contract is uploaded on the blockchain, which involves no intermediate code. Although ​privacy is slightly compromised, transparency is increased.

Updated 5 months ago

5.1 Hello World!


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.