All about Functions

Learn more about functions and constructors in Solidity.

We'll cover the following...

We’ve already covered the basics of defining functions in Solidity, but in this lesson, we'll spend a bit more time learning the nuances of how we can use and define functions. While functions in Solidity work similarly to other programming languages, there are a few differences, and we'll cover them in this lesson.

Constructors

Similar to object-oriented programming languages, Solidity allows defining a constructor to initialize a smart contract before users can interact with it. Just like a regular function, a constructor accepts a list of parameters, and a user that deploys a smart contract must provide values for all of them.

To define a constructor, we need to use the constructor keyword and specify the list of parameters required for a contract’s initialization.

contract HelloWorld {
uint number;
constructor(uint initNumber) {
number = initNumber;
}
}

In Solidity, a smart contract can have only one ...