Solidity Smart Contract Tutorial: Build Your First Contract 2026

EifaSoft Smart Contract Team
Solidity Smart Contract Tutorial: Build Your First Contract 2026

📘 Cluster Guide: This article supports our pillar guide on Smart Contract Development. For security patterns, see Smart Contract Security Best Practices.

Solidity Smart Contract Tutorial: Build Your First Contract

What You Will Build

By the end of this tutorial, you will have:

  1. Set up a Foundry development environment
  2. Written an ERC-20 token with minting, burning, and access control
  3. Written tests with 95%+ coverage
  4. Deployed to Sepolia testnet
  5. Verified source code on Etherscan

Step 1: Install Foundry

# macOS / Linux
curl -L https://foundry.paradigm.xyz | bash
foundryup

# Windows (PowerShell)
Invoke-WebRequest https://win.foundry.paradigm.xyz -OutFile foundryup.exe
.\foundryup.exe

Create a new project:

forge init my-token
cd my-token

Step 2: Install OpenZeppelin

forge install OpenZeppelin/openzeppelin-contracts

Add to remappings.txt:

@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/

Step 3: Write the Contract

Create src/MyToken.sol:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";

contract MyToken is ERC20, AccessControl, Pausable {
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
    uint256 public constant MAX_SUPPLY = 100_000_000 * 10**18;

    constructor(address admin) ERC20("My Token", "MTK") {
        _grantRole(DEFAULT_ADMIN_ROLE, admin);
        _grantRole(MINTER_ROLE, admin);
    }

    function mint(address to, uint256 amount)
        external onlyRole(MINTER_ROLE) whenNotPaused
    {
        require(totalSupply() + amount <= MAX_SUPPLY, "Cap exceeded");
        _mint(to, amount);
    }

    function burn(uint256 amount) external whenNotPaused {
        _burn(msg.sender, amount);
    }

    function pause() external onlyRole(DEFAULT_ADMIN_ROLE) {
        _pause();
    }

    function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) {
        _unpause();
    }
}

Step 4: Write Tests

Create test/MyToken.test.sol:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "forge-std/Test.sol";
import "../src/MyToken.sol";

contract MyTokenTest is Test {
    MyToken token;
    address admin = address(1);
    address user = address(2);

    function setUp() public {
        token = new MyToken(admin);
    }

    function testMint() public {
        vm.prank(admin);
        token.mint(user, 1000 * 10**18);
        assertEq(token.balanceOf(user), 1000 * 10**18);
    }

    function testCannotMintOverCap() public {
        vm.prank(admin);
        vm.expectRevert("Cap exceeded");
        token.mint(user, 100_000_001 * 10**18);
    }

    function testNonMinterCannotMint() public {
        vm.prank(user);
        vm.expectRevert();
        token.mint(user, 1000 * 10**18);
    }

    function testBurn() public {
        vm.prank(admin);
        token.mint(user, 1000 * 10**18);
        vm.prank(user);
        token.burn(500 * 10**18);
        assertEq(token.balanceOf(user), 500 * 10**18);
    }

    function testPauseBlocksMint() public {
        vm.prank(admin);
        token.pause();
        vm.prank(admin);
        vm.expectRevert();
        token.mint(user, 1000 * 10**18);
    }
}

Run tests:

forge test -vv

Run with coverage:

forge coverage

Step 5: Deploy to Testnet

Create script/Deploy.s.sol:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "forge-std/Script.sol";
import "../src/MyToken.sol";

contract DeployScript is Script {
    function run() external {
        uint256 deployerKey = vm.envUint("PRIVATE_KEY");
        vm.startBroadcast(deployerKey);
        new MyToken(vm.addr(deployerKey));
        vm.stopBroadcast();
    }
}

Deploy to Sepolia:

export PRIVATE_KEY=0x...
forge script script/Deploy.s.sol --rpc-url $SEPOLIA_RPC --broadcast --verify --etherscan-api-key $ETHERSCAN_KEY

Step 6: Verify on Etherscan

If not auto-verified during deployment:

forge verify-contract <DEPLOYED_ADDRESS> src/MyToken.sol:MyToken --chain sepolia --etherscan-api-key $ETHERSCAN_KEY

Next Steps

After mastering this tutorial:

  1. Add vesting contracts for team/investor tokens
  2. Implement governance with OpenZeppelin Governor
  3. Add a staking contract for yield distribution
  4. Get an audit before mainnet deployment
  5. Set up monitoring with Tenderly

Full production guide: Smart Contract Development: Complete 2026 Guide.

FAQ Section

1. Why Foundry instead of Hardhat?

Foundry is 20x faster for tests, has built-in fuzzing, and writes tests in Solidity (no JavaScript/TypeScript bridge). Hardhat is still valid for teams with strong JS backgrounds, but Foundry is the 2026 industry standard for security-focused development.

2. How long does it take to learn Solidity?

2-4 weeks for basic contracts (tokens, NFTs), 8-12 weeks for DeFi protocol patterns, 6+ months for security expertise. Start with this tutorial, then build progressively complex contracts.

3. What is the best Solidity version?

Solidity 0.8.24+ — built-in overflow checks, custom errors, transient storage, and all modern security features. Never use 0.7.x or earlier for new projects.

4. Do I need to pay gas to deploy contracts?

Yes on mainnet (₹50K-₹2L for Ethereum, ₹5K-₹15K for BSC/Polygon). No on testnets — use Sepolia/Amoy faucets for free test ETH. Always test thoroughly before mainnet deployment.

5. Can EifaSoft help me build production smart contracts?

Yes. Our team has deployed 120+ audited contracts and can take your project from this tutorial level to production-grade with security audits, gas optimization, and mainnet deployment support. Contact us to discuss your project.

Get Professional Smart Contract Development

EifaSoft Technologies — from first contract to production deployment with 120+ audited contracts and zero exploits.

Start Your Project →

Related Resources:

Share this article:

Ready to Transform Your Ideas into Reality?

Let's discuss your next blockchain, mobile app, or web development project

Schedule Free Consultation
📞 GET IN TOUCH

Request a Free Consultation

Let us help transform your business with cutting-edge technology

Form completion0%
100% Secure
No Spam
Quick Response