# Week 7 at Blockfuse Labs – Learning the Basics of Solidity This week at **Blockfuse Labs**, my learning journey took me into the world of **Solidity**, the programming language used to write smart contracts on Ethereum. Solidity is to Ethereum what JavaScript is to websites — it’s the language that brings decentralized applications (dApps) to life. Here are the **fundamental concepts** I explored in Week 7. ## What is Solidity? Solidity is a **high-level, contract-oriented language** designed for the Ethereum Virtual Machine (EVM). With Solidity, developers can: * Build **smart contracts** (self-executing agreements). * Manage and transfer **Ether (ETH)**. * Create decentralized apps like **DeFi protocols, NFTs, and DAOs**. ## Structure of a Solidity Contract Every contract starts with two things: ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract HelloWorld { string public message = "Hello, Blockchain!"; } ``` * `pragma solidity ^0.8.0;` → sets compiler version. * `contract HelloWorld { ... }` → defines the contract. * `string public message` → a **state variable** stored on the blockchain. ## 3️⃣ State Variables State variables are like **permanent storage** on the blockchain. ```solidity uint public balance; ``` * Stored **on-chain**. * Updating them costs **gas**. --- ## Functions Functions define what the contract can do. ```solidity function setMessage(string memory _msg) public { message = _msg; } ``` * `public` → anyone can call it. * `memory` → temporary storage for inputs. * Updates the **message** stored on-chain. ## 5️⃣ Data Types I also learned about Solidity’s basic data types: * `uint` → whole numbers (0, 1, 2…) * `int` → signed numbers (-1, 0, 1…) * `bool` → true / false * `address` → Ethereum wallet/contract * `string` → text --- ## 6️⃣ Function Visibility Functions can be restricted using visibility keywords: * `public` → anyone can call * `private` → only this contract * `internal` → this + child contracts * `external` → only callable from outside ## Payable (Handling ETH) To make a function receive ETH, it must be `payable`: ```solidity function deposit() public payable {} ``` * Allows ETH deposits into the contract. * Amount sent is stored in `msg.value`. --- ## Events Events log activities on the blockchain. ```solidity event MessageUpdated(string newMessage); function setMessage(string memory _msg) public { message = _msg; emit MessageUpdated(_msg); } ``` Frontend apps can listen to these events to react when something changes. ## Mini Project – SimpleBank To practice, I built a simple bank contract: ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract SimpleBank { mapping(address => uint) public balances; function deposit() public payable { balances[msg.sender] += msg.value; } function withdraw(uint _amount) public { require(balances[msg.sender] >= _amount, "Not enough funds"); balances[msg.sender] -= _amount; payable(msg.sender).transfer(_amount); } } ``` ## Key Takeaways from Week 7 * Solidity is the **language of Ethereum smart contracts**. * Contracts store data in **state variables** and act through **functions**. * **Visibility** defines who can access a function or variable. * **Payable functions** let contracts handle ETH. * **Events** act like blockchain logs for external apps. * Gas is needed for storage and execution. Week 7 gave me a solid foundation in Solidity. From here, I’m excited to dive into **more advanced topics** like modifiers, inheritance, libraries, gas optimization, and contract security in the coming weeks.