Your First Smart Contract with Solidity: From Zero to Deployed in 30 Minutes

If you've ever wondered what writing a smart contract actually feels like — beyond the hype — this is the most direct path I can give you. No wallets to fund with real money, no theory upfront. We're deploying a real ERC-20 token to Sepolia testnet, end to end, in about half an hour.

What you'll need

  • Node.js 20+ installed
  • A MetaMask wallet (free, browser extension)
  • Some Sepolia ETH from a faucet (free, takes 2 minutes)

That's it. No paid services, no credit card.

Step 1: Set up the project

mkdir my-first-token && cd my-first-token
npm init -y
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
npx hardhat init

Pick "Create a JavaScript project" when Hardhat asks. It scaffolds a working repo with sample contracts.

Step 2: Write the contract

Replace contracts/Lock.sol with this:

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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor() ERC20("MyToken", "MTK") {
        _mint(msg.sender, 1000 * 10 ** decimals());
    }
}

Install the OpenZeppelin contracts:

npm install @openzeppelin/contracts

That's the entire contract. 8 lines. It creates a token called "MyToken" with the symbol "MTK", and mints 1000 of them to whoever deploys it.

Step 3: Why OpenZeppelin matters

You could write the ERC-20 standard yourself. But the OpenZeppelin implementation has been audited dozens of times, used in billions of dollars of contracts, and battle-tested for edge cases (integer overflows, reentrancy patterns around transfers, etc.) that you wouldn't catch on a first pass.

Rule of thumb in production: never reimplement a standard that has a reference library. The risk-to-reward is terrible.

Step 4: Configure the network

Create a .env file (and add it to .gitignore immediately):

SEPOLIA_RPC_URL=https://ethereum-sepolia-rpc.publicnode.com
PRIVATE_KEY=<your_metamask_private_key>

To get your private key from MetaMask: account menu → Account details → Show private key. Never use a wallet that holds real funds for testing. Create a fresh one.

Edit hardhat.config.js:

require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();

module.exports = {
  solidity: "0.8.20",
  networks: {
    sepolia: {
      url: process.env.SEPOLIA_RPC_URL,
      accounts: [process.env.PRIVATE_KEY],
    },
  },
};

Install dotenv:

npm install dotenv

Step 5: Get Sepolia ETH

Go to any of these faucets and paste your MetaMask address:

  • https://sepoliafaucet.com
  • https://www.alchemy.com/faucets/ethereum-sepolia

You need about 0.05 ETH. It arrives in under a minute.

Step 6: Deploy

Create scripts/deploy.js:

const hre = require("hardhat");

async function main() {
  const Token = await hre.ethers.getContractFactory("MyToken");
  const token = await Token.deploy();
  await token.waitForDeployment();
  console.log("MyToken deployed to:", await token.getAddress());
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Run it:

npx hardhat run scripts/deploy.js --network sepolia

Output:

MyToken deployed to: 0x4f3e1b...c2a9

That address is now a real ERC-20 contract on Sepolia. Anyone in the world can read from it.

Step 7: Verify it exists

Open https://sepolia.etherscan.io and paste the address. You'll see:

  • The contract was deployed by your wallet
  • Your wallet now holds 1000 MTK
  • The transaction is permanent and public

What you actually learned

The 30 minutes you just spent contain most of the mental model you need for Web3 development:

  1. Contracts are deterministic functions deployed to a public computer. They don't run on your machine.
  2. State changes cost gas. Reads are free. Writes cost ETH.
  3. You don't write standards from scratch. You import audited ones.
  4. Testnets are free playgrounds. Mainnet is identical, with real money attached.

Next steps that actually teach you something

  • Add a transfer test using Hardhat's testing framework
  • Try minting on a transfer (you'll quickly understand why _mint is internal)
  • Deploy the same contract to Base Sepolia (a Layer 2) and compare gas costs

If you go down that rabbit hole, you'll find yourself asking: "When should I use Ethereum directly vs an L2?" That's exactly the topic of the next article.

Want to go deeper?

This article is a small slice of what we teach in the Blockchain Development Diploma at UNLu. The full program covers EVM internals, Solidity security patterns, DeFi, L2 deployments, and a complete USDC payment gateway as the capstone.

Explore the Blockchain Diploma