Session 02.2
Smart Contracts

SOLIDITY
PROGRAMMING.

The syntax of the Ethereum Virtual Machine. Learn to write type-safe, gas-efficient, and secure smart contracts using modern Solidity patterns.

Modules

/usr/bin/solidity --module 1

Contract Anatomy

Solidity contracts operate similarly to classes in OOP. They encapsulate state (storage) and logic (functions). Every contract is a deployed instance on the global ledger.

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

contract Vault {
    // State Variable (Stored on-chain)
    uint256 public balance;

    // Constructor (Runs once)
    constructor() {
        balance = 100;
    }

    // Function (Modifies state)
    function deposit(uint256 amount) public {
        balance += amount;
    }
}

Compilers Note

Critical concepts for production deployment.

Contracts are immutable: deploy once, run forever (mostly).

Storage is the most expensive resource; pack your variables.

Security is paramount: reentrancy and overflow checks are mandatory.