You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Solidity is the most widely used programming language for writing smart contracts on Ethereum and EVM-compatible blockchains. It is a statically typed, object-oriented language influenced by JavaScript, Python, and C++.
| Tool | Purpose |
|---|---|
| Remix IDE | Browser-based IDE for quick prototyping (remix.ethereum.org) |
| Hardhat | JavaScript/TypeScript development framework for testing and deployment |
| Foundry | Rust-based toolkit with fast compilation and testing (forge, cast, anvil) |
| OpenZeppelin | Library of audited, reusable smart contract components |
| Slither | Static analysis tool for finding vulnerabilities |
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract SimpleStorage {
// State variable (stored on-chain)
uint256 private storedValue;
// Event emitted when value changes
event ValueChanged(uint256 newValue);
// Function to set the value
function set(uint256 _value) public {
storedValue = _value;
emit ValueChanged(_value);
}
// Function to get the value (view = no state modification)
function get() public view returns (uint256) {
return storedValue;
}
}
| Element | Description |
|---|---|
| pragma | Specifies the compiler version |
| contract | Similar to a class in other languages |
| State variables | Stored permanently on the blockchain |
| Functions | Executable units of code |
| Events | Log entries that external applications can listen to |
| Type | Description | Example |
|---|---|---|
| bool | Boolean (true/false) | bool isActive = true; |
| uint256 | Unsigned 256-bit integer | uint256 balance = 1000; |
| int256 | Signed 256-bit integer | int256 temperature = -10; |
| address | 20-byte Ethereum address | address owner = msg.sender; |
| bytes32 | Fixed-size byte array | bytes32 hash = keccak256("data"); |
| enum | User-defined enumeration | enum Status { Active, Paused } |
| Type | Description | Example |
|---|---|---|
| string | Dynamic-size UTF-8 string | string name = "Token"; |
| bytes | Dynamic-size byte array | bytes data = hex"0123"; |
| array | Fixed or dynamic size | uint256[] values; |
| mapping | Key-value store | mapping(address => uint256) balances; |
| struct | Custom data structure | struct User { string name; uint age; } |
| Visibility | Description |
|---|---|
| public | Accessible from anywhere (external, internal, derived contracts) |
| private | Only accessible within the contract that defines it |
| internal | Accessible within the contract and derived contracts |
| external | Only callable from outside the contract (not internally without this) |
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.