Learning about the fundamental programming structure in Solidity
Let’s get a taste of Solidity’s code and use an example to show you the layout and constructs of a smart contract. We will begin with the most basic smart contract example, HelloWorld.sol
, as shown in the following screenshot:
Figure 6.4 – HelloWorld contract
Solidity’s file extension is .sol
. It is similar to .js
for JavaScript files and .java
for Java source code. The preceding code defines a smart contract called HelloWorld
, which has a contractor for setting the initial greeting, defines a setGreeting
method to reset the greeting, and a hello
method for the authorized party to get the greeting. In the rest of the chapter, we will go over the fundamentals of the Solidity programming language, including the following headings:
- The layout of a Solidity source file
- Structure of a contract
- State variables
- Functions
- Function modifiers