🏠 Home
Beginner
01 — Introduction to Solidity 02 — Setting Up Your Environment 03 — Your First Smart Contract 04 — Data Types & Variables 05 — Functions & Visibility 06 — Control Flow 07 — Arrays & Mappings 08 — Structs & Enums
Intermediate
09 — Events & Logging 10 — Modifiers 11 — Inheritance 12 — Interfaces & Abstract Contracts 13 — Error Handling 14 — Ether & Wei 15 — Payable Functions 16 — msg.sender & msg.value 17 — Storage vs Memory vs Stack
Advanced
18 — Gas Optimization 19 — ERC-20 Tokens 20 — ERC-721 NFT Standard 21 — Contract Security 22 — Reentrancy Attacks 23 — Oracles & Chainlink 24 — Upgradeable Contracts 25 — Deploying to Mainnet
SolidityMaster / Lesson 25
Lesson 25 of 25

Deploying to Mainnet

Testnets, Etherscan verification, deployment scripts, and going live safely.

Advanced

Pre-Deployment Checklist

Before deploying to mainnet with real money at stake:
  • ✅ All tests pass (unit + integration)
  • ✅ Security audit completed (or at minimum a self-audit)
  • ✅ Tested on Sepolia/Goerli testnet
  • ✅ Gas costs benchmarked and optimized
  • ✅ Contract verified on Etherscan
  • ✅ Emergency pause mechanism in place
  • ✅ Upgrade path defined (if needed)
  • ✅ Multi-sig owner (not single EOA)

Hardhat Deployment Script

Use Hardhat Ignition (or scripts) for reproducible, trackable deployments.
Solidity
// scripts/deploy.js
const { ethers } = require("hardhat");

async function main() {
    const [deployer] = await ethers.getSigners();
    console.log("Deploying with:", deployer.address);
    console.log("Balance:", ethers.formatEther(
        await ethers.provider.getBalance(deployer.address)), "ETH");

    const MyContract = await ethers.getContractFactory("MyContract");

    // Deploy with constructor args
    const contract = await MyContract.deploy("arg1", 42, {
        gasLimit: 500_000, // explicit gas limit
    });

    await contract.waitForDeployment();
    const addr = await contract.getAddress();
    console.log("Deployed to:", addr);

    // Verify on Etherscan
    if (network.name !== "hardhat") {
        console.log("Waiting for confirmations...");
        await contract.deploymentTransaction().wait(5);
        await run("verify:verify", {
            address: addr,
            constructorArguments: ["arg1", 42],
        });
    }
}

main().catch(console.error);

Hardhat Config for Mainnet

Configure networks, gas settings, and API keys in hardhat.config.js.
Solidity
// hardhat.config.js
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();

module.exports = {
    solidity: {
        version: "0.8.24",
        settings: {
            optimizer: { enabled: true, runs: 200 },
            viaIR: true, // enables more aggressive optimization
        }
    },
    networks: {
        sepolia: {
            url: process.env.SEPOLIA_RPC_URL,
            accounts: [process.env.PRIVATE_KEY],
            gasPrice: "auto",
        },
        mainnet: {
            url: process.env.MAINNET_RPC_URL,
            accounts: [process.env.PRIVATE_KEY],
            gasPrice: "auto",
        }
    },
    etherscan: {
        apiKey: process.env.ETHERSCAN_API_KEY,
    },
    gasReporter: {
        enabled: true,
        currency: "USD",
        coinmarketcap: process.env.CMC_API_KEY,
    }
};

Congratulations!

🎉 You've completed all 25 lessons of SolidityMaster! You now have the knowledge to build, secure, and deploy production-grade smart contracts on Ethereum. Your next steps:
  • Build a full project: DEX, NFT marketplace, or DAO
  • Study real audit reports on Code4rena
  • Contribute to open source: OpenZeppelin, Uniswap, Aave
  • Practice CTF challenges on Ethernaut
  • Read the official Solidity documentation
🚀 Ready to build a real blockchain project?

Try this hands-on tutorial: Create a Cryptocurrency Using Truffle (MetaCoin Project)