0Pricing
Web3 & DApp Development Fundamentals · Lesson

Functions & Control Structures

Learn to define functions, use visibility modifiers (public, private, internal, external), and implement control flow (if/else, loops).

What are Functions in Solidity?

Functions are named blocks of code that perform specific tasks within your smart contract. They are fundamental for organizing your contract's logic, making it reusable, and improving readability.

Think of functions as the actions or operations your smart contract can perform, like calculating a value or updating a state variable.

Defining Your First Function

A basic function includes the function keyword, a name, optional parameters, a visibility specifier, and an optional return type. Here's a simple function that returns a greeting:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract MyFirstFunctions {
  function greet() public pure returns (string memory) {
    return "Hello, CoddyKit!";
  }
}

All lessons in this course

  1. Introduction to Solidity
  2. Variables & Data Types
  3. Functions & Control Structures
← Back to Web3 & DApp Development Fundamentals