Solidity Tutorial — Write and Deploy Your First Smart Contract
In this tutorial, you'll learn about Solidity Tutorial. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
What You'll Learn
Write your first Solidity smart contract, compile it with Remix, deploy to a testnet, and interact with it — all in 10 minutes.
Why It Matters
Solidity is the primary language for Ethereum smart contracts. Learning it opens the door to DeFi, NFTs, DAOs, and all of Web3 development.
Real-World Use
Creating your own cryptocurrency token, building a crowdfunding contract, or deploying an NFT collection.
Prerequisites
No prior Blockchain knowledge needed. Just a browser — we'll use Remix IDE (remix.Ethereum.org).
Step 1: Open Remix
Go to [remix.Ethereum.org](https://remix.Ethereum.org). It's a browser-based IDE for Solidity.
Step 2: Write Your Contract
Create a new file Counter.sol:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Counter {
uint256 private count;
event CountIncremented(uint256 newCount);
constructor() {
count = 0;
}
function increment() public {
count += 1;
emit CountIncremented(count);
}
function decrement() public {
require(count > 0, "Counter cannot go below 0");
count -= 1;
}
function getCount() public view returns (uint256) {
return count;
}
function reset() public {
count = 0;
}
}
Step 3: Compile
- Click the Solidity Compiler tab (second icon down)
- Click Compile Counter.sol
- You should see a green checkmark — no errors
Step 4: Deploy to Test Network
- Click the Deploy & Run Transactions tab
- Under Environment, select Injected Provider — MetaMask
- Connect MetaMask and select the Sepolia testnet
- Click Deploy
- Confirm the Transaction in MetaMask
Step 5: Interact
After deployment, you'll see your contract under Deployed Contracts:
- Click
increment— confirms a Transaction - Click
getCount— shows1 - Click
decrement— back to0 - Click
reset— note: it doesn't need ETH (it's a state change, but no value transfer)
Deploying to Mainnet
# Mainnet deployment requires real ETH for gas
# NEVER deploy untested code to mainnet
Practice
Modify the contract to:
- Store the address of who last incremented
- Add a maximum count limit
- Only allow the contract owner to reset
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro