Smart Contract 101: What is the Structure of a Contract?

20201028_what is the sturucture of a contract_feature.jpg

以下是简单的智能合约的示例。让我们观察合同的结构,并浏览其代码的每一行。

另外,有两个函数:setName()和getName()。

setName takes a string input name. Its type of visibility is public, which means it can be called both internally and externally. Inside the function, the parameter name will be replacing the existing value stored by _name. As this function will change data on the blockchain, it will cost ether.

Another function getName, view means the function is read-only. This function returns a string value _name which is the same as the one we stored on the blockchain.

上述组件的组合创建了一个简单的智能合约。

In the next lesson, we will describe the life-cycle of developing smart contracts.

原创文章,作者:Johnny Chiu,如若转载,请注明出处:https://www.kaixuan.pro/news/318793/