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:
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 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 this section, we will go over the fundamentals of the Solidity programming language, including the following:
- The layout of a Solidity source file
- Structure of a contract
- State variables
- Functions
- Function modifiers