Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the structure of solidity code?

Shulou Source: shulou.com Published: 2022-06-02 07:34:29 09月27日 Update

This article mainly introduces "what is the structure of solidity code". In daily operation, I believe many people have doubts about the structure of solidity code. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what is the structure of solidity code?" Next, please follow the editor to study!

Contract structure

1. Specify the version number of solidity.

This line means that we are preventing our program from being compiled by a compiler older than 0.4.0 ^ for upward compatibility, but cannot be compiled by a compiler of 0.5.0 or above.

We do this to minimize the risk of errors that may occur when the code is compiled in an unexpected or incompatible manner.

2. Define a contract with different methods and attributes. Describe an object from two aspects: attribute and behavior, which is an important feature of object-oriented.

3. The methods and properties of declaring variables inside the contract.

4. Define different functions and belong to different function members.

Code structure

General form of function 1

Function () {public | internal | external} [pure | constant | view | payable] [returns ()]

Function

Function modifier

Public: anyone can call this function, including the consumer of DApp.

Private: only the contract itself can call this function (in another function).

Internal: only this contract and all contracts resulting therefrom can be called a contract.

External: this function can only be called externally, but not internally by the contract.

View: it can be called freely, because it only "views" the state of the block chain without changing it.

Pure: can also be called freely, neither reading nor writing to the block chain

Payable: often used to send tokens to the contract address.

Modifier

At this point, the study of "what is the structure of solidity code" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Function code structure contract compilation learning different only contract method freedom block object attribute more compiler help practical important unexpected Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker Redmi Microsoft Xiaomi