Learn the fundamentals of Solidity, including how to set up your development environment and write your first smart contract.
pragma solidity ^0.8.0;
contract HelloWorld {
string public greet = "Hello, World!";
}Understand different data types and how to declare variables in Solidity.
contract DataTypes {
uint public myUint = 1;
string public myString = "Hello";
address public myAddress = msg.sender;
}Explore how to define functions, use function modifiers, and understand their significance.
contract Functions {
uint public myNumber;
function setNumber(uint _number) public {
myNumber = _number;
}
function getNumber() public view returns (uint) {
return myNumber;
}
}Dive into contract inheritance and interface implementation to create more modular and reusable code.
contract Parent {
function sayHello() public pure returns (string memory) {
return "Hello from Parent";
}
}
contract Child is Parent {
function greet() public pure returns (string memory) {
return sayHello();
}
}This repo is organized by topic folders:
1-Intro2-State Variables3-Local Variables4-Function5-Constructor6-Data Types7-Array8-Loops9-Conditionals10-Struct11-Mapping12-Storage Locations13-Global Variables14- Contract Balance15-Visibility16-Exercises
Follow folders in order from 1-Intro to 16-Exercises. Each folder contains simple examples for the topic, with 16-Exercises providing TODO-based practice.
There is no single "run" command for the entire repo. Each .sol file is a separate contract that you compile and deploy.
- Open Remix: https://remix.ethereum.org
- Create a workspace and import the folder you want (e.g.,
7-Array). - Open a
.solfile in that folder. - Set the compiler version to match the file
pragma. - Compile and deploy.
- Interact with the contract functions in the Remix UI.
Repeat the same steps for each folder and file you want to try.
- Copy one folder at a time into
contracts/(for example7-Array/). - Compile with
npx hardhat compile. - Create a script to deploy and interact with a specific contract.
Example script outline:
// scripts/run.js
const { ethers } = require("hardhat");
async function main() {
const Contract = await ethers.getContractFactory("ContractNameHere");
const contract = await Contract.deploy();
await contract.waitForDeployment();
console.log("Deployed:", await contract.getAddress());
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});Run it with:
npx hardhat run scripts/run.jsRepeat by swapping the folder and contract name you want to test.
Remix is a browser-based IDE, so there is nothing to install to compile or run these contracts.
- A modern web browser (Chrome, Firefox, or Edge).
- Optional: MetaMask if you want to deploy to a testnet. For local testing, Remix VM is enough.
- Open Remix: https://remix.ethereum.org
- Create a workspace:
- Use File explorers > Workspaces > Create and name it (e.g.,
solidity-basics).
- Use File explorers > Workspaces > Create and name it (e.g.,
- Add the contracts:
- Drag and drop the folder(s) from this repo into the Remix file explorer, or
- Copy the
.solfiles into matching folders in Remix.
- Compile:
- Open the Solidity Compiler tab.
- Set the compiler version that matches the
pragmain the file. - Click Compile.
- Deploy and run:
- Open the Deploy & Run Transactions tab.
- Choose Remix VM as the environment for local testing.
- Click Deploy, then interact with the functions below.
- None required for Remix-only usage.
Use this if you want to compile and test locally with Node.js.
- Node.js 18+ and npm (install from https://nodejs.org)
Run these commands from the repo root:
npm init -y
npm install --save-dev hardhat
npx hardhat init- Copy the folder(s) you want into the
contracts/directory, or - Move all
.solfiles intocontracts/and keep the folder structure.
npx hardhat compileCreate a script in scripts/ and run:
npx hardhat run scripts/yourScript.jsThe 16-Exercises folder contains TODO-based practice files. Start with 01_AddressBook.sol and work in order.
No automated tests are included. Use Remix or Hardhat to manually deploy and interact.
Contributions are welcome for typos, clarity improvements, or new examples. Keep changes small and focused.
Add a license file if you plan to distribute or reuse this material.