Structure of a contract

Just like in an object-oriented language such as Java, where we have classes, similarly we have contracts in Solidity languages. Each Solidity contract can contain declarations of one or many state variables, constants, a constructor function, enumerations types, function modifiers, events, functions, and struct types. Furthermore, a contract can inherit from other contracts as well.

You can also define special kinds of contracts called libraries and interfaces. Libraries are deployed only once along with your contract deployment. Interfaces cannot have function definitions, variables, struct types, or enums. We have a separate chapter where we will talk about libraries and interfaces in detail.

Normally, the structure of these constructs is maintained in the following order. Although there is no hard rule for it, it would be good to maintain this order so that other developers can also understand the code at a glance:

  1. Global state variables of contract
  2. Enum types
  3. Struct types
  4. Function modifier definitions
  5. Events definitions
  6. Functions 

We will have a brief overview of the state variables, functions, events, and struct types that create the contract structure. We will discuss these topics in detail in the further sections of this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.81.73