Skip to content

Solidity Tutorial — Write and Deploy Your First Smart Contract

DodaTech 2 min read

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

  1. Click the Solidity Compiler tab (second icon down)
  2. Click Compile Counter.sol
  3. You should see a green checkmark — no errors

Step 4: Deploy to Test Network

  1. Click the Deploy & Run Transactions tab
  2. Under Environment, select Injected Provider — MetaMask
  3. Connect MetaMask and select the Sepolia testnet
  4. Click Deploy
  5. Confirm the Transaction in MetaMask

Step 5: Interact

After deployment, you'll see your contract under Deployed Contracts:

  1. Click increment — confirms a Transaction
  2. Click getCount — shows 1
  3. Click decrement — back to 0
  4. 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:

  1. Store the address of who last incremented
  2. Add a maximum count limit
  3. Only allow the contract owner to reset

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro