Functions and Visibility Modifiers
Understand how to define functions, manage their visibility (public, private, internal, external), and handle function parameters and return values.
Functions: Your Contract's Actions
Welcome to Lesson 3! Today, we'll dive into functions in Solidity. Think of functions as the actions or operations your smart contract can perform.
They allow you to organize your code, make it reusable, and define how users (or other contracts) can interact with your contract's data and logic.
Defining a Simple Function
Every function needs a name and a body where its code lives. Here's the basic structure:
- Keyword
function - Function name (e.g.,
greet) - Parentheses
()for parameters - Curly braces
{}for the code block
Let's see a very simple example.
All lessons in this course
- Solidity Data Types and Variables
- Control Structures and Loops
- Functions and Visibility Modifiers
- Structs and Enums