The structure of a contract
The primary purpose of Solidity is to write smart contracts for Ethereum. Smart contracts are the basic unit of deployment and execution for EVMs. Although all chapters in this book are dedicated to writing and developing smart contracts, the basic structure of smart contracts is discussed in this section.
Technically, smart contracts have two major elements – variables and functions. There are multiple facets to both variables and functions in Solidity, and that is again something that will be discussed throughout this book. This section is about describing the general structure of a smart contract using the Solidity language.
A contract consists of the following multiple constructs:
- State variables
- Structure definitions
- Modifier definitions
- Event declarations
- Enumeration definitions
- Function definitions
The next code listing shows various elements available to a smart contract. Each of these elements will...