Lesson 1 of 0
In Progress
Class 14
Class 14 – Blockchain & Smart Contract Basics
Slides:Class14
This lecture focuses on functions in Solidity, a critical component in Ethereum’s smart contracts.
Key Points Covered:
- Functions in Solidity:
- Functions are the heart of Ethereum blockchain and Solidity. They allow reading from and writing to state variables, and their execution results in transactions.
- Solidity provides both named functions and an unnamed fallback function within a contract.
- Function Syntax:
- Functions are defined using the
functionkeyword followed by a unique name. - Functions may take parameters and return values.
- The structure of a function includes a statement block surrounded by curly brackets
{}.
- Functions are defined using the
- Visibility Qualifiers:
- Public: Functions can be called internally and externally.
- Internal: Functions can only be used within the contract or derived contracts.
- Private: Functions are restricted to the declaring contract.
- External: Functions can be called externally but not internally.
- Behavior Qualifiers:
- View: Functions that do not modify the blockchain state but can read from it.
- Pure: Functions that neither read nor modify state variables.
- Payable: Functions that accept Ether transactions.
- Returning Data:
- Functions in Solidity can return single or multiple values.
- Two methods for returning values:
- Specifying the datatype only.
- Specifying both the datatype and the variable name.
- Solidity supports returning multiple values as a tuple.
- Function Calling:
- Functions are invoked by writing their name.
- Multiple parameters can be passed when calling a function.
This lecture provides the foundation needed to understand and implement functions in Solidity, ensuring that code is efficient and manageable.
