8.3 Contract Development with Cocos Terminal

Cocos Terminal adds Contract Manage function in Toolkits for​ developers to create, update contracts, and execute contract interfaces directly.

Contract Development

1. Introduction

a. Log in to Terminal
b. Click Contract Manage in the left directory bar to view various information about the contracts existed under this account, including the basic information of the contract, code, interface, data zone (public_data), etc., as shown below:

2. Create a contract

a. Click Add to create a new contract.

b. Fill in the contract name in the pop-up window. The contract name should be 4-63 characters consisting of lowercase letters or numbers​ and starts with "contract.", for example, "contract.testnew"

3. Edit contract code, and update existing contracts

function hello()
    chainhelper:log('Hello World! contract.testnew')
end

4. Release contract

a. Click Release

b. Click Random Generation. If the contract opens the permission validation, the app_keys configuration entry of JS-SDK must be filled with the key. It is recommended to copy and save the key.

c. Click OK. Contract​ creation requires a certain fee.

5. Call the contract

a. After the contract is released, you can find the interface of the contract as directed by the arrow in the picture below. Click Interfaces to fill in the parameters to execute the interface.

b. It requires a certain fee to call the contract.

c. The result of the call will be displayed below the editing area

6. Update contract

a. Use init_data () to initialize the data

function hello()
    chainhelper:log('Hello World! contract.testnew')
end

function hello2(num,amount)
	chainhelper:log('=======loooooog starts=======');
	chainhelper:log('{"num": "'..num..'","amount":"'..amount..'"}');
	chainhelper:log('=======log ends=======');
end

function init_data()
    read_list = {public_data={initdata=true}}
    chainhelper:read_chain()
    public_data.initdata  = 98
    write_list = {public_data={initdata=true}}
    chainhelper:write_chain()
end

b. Click Release Contract (the existing contract will be updated to the latest). After the release is done, the init_data() interface must be called to initialize the data.

c. Click Data to initialize the data.

7. View contract

You can also fill in the contract name in the search box to view the contract info and statistics.

a. View contract basic information

b. Contract statistics. It is convenient to check operational data including the number of contract calls, the number of tokens transferred in and out.

Contract Statistics

a. The ranking of hot contracts is also provided in Terminal, enabling a clear view of the number of contract calls, as well as a quick view of the contract details and the execution results of the contract.

b. Click the contract to view the contract code, data and statistics.

8.3 Contract Development with Cocos Terminal


Cocos Terminal adds Contract Manage function in Toolkits for​ developers to create, update contracts, and execute contract interfaces directly.

Suggested Edits are limited on API Reference Pages

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