Deploy Your First Smart Contract with Hardhat: Beginner-Friendly Step-by-Step Guide

Table of contents

A Complete Beginnerโ€™s Guide to Writing and Deploying Smart Contracts on Ethereum Using Hardhat

After writing a few contracts in Remix, I knew it was time to move to something more powerful. Hardhat is a professional-grade development toolchain that makes writing, testing, and deploying Solidity smart contracts locally easy.

It keeps coming up in conversations among serious Solidity developers, and for good reason. But when I tried to get started, most setup tutorials either lacked real context or skipped critical steps.

I wrote this guide as I was figuring it out myself. If you're about to take that leap from browser-based development to a local environment and want someone to walk you through it slowly, this article is for you.

I'll explain exactly what each file and command does and how to go from zero to having a working smart contract locally on your machine, tested, and deployed.

Let's get started by creating your first local smart contract using Hardhat.

TL;DR: How to Deploy Your First Smart Contract with Hardhat

  • ๐Ÿง  Install Node.js, VS Code, MetaMask

  • ๐Ÿ“ฆ Scaffold your Hardhat project

  • โœ๏ธ Write and compile a TipJar contract

  • ๐Ÿงช Test it locally with Hardhat's console

  • ๐Ÿš€ Deploy to Sepolia with MetaMask + Alchemy

  • ๐ŸŒ Verify it on Etherscan

  • ๐Ÿ“‚ Push your repo to GitHub

โœ… From zero to deployed, this guide is designed for beginners and is fully aligned with real-world applications.

By the end, you will confidently deploy your first smart contract and be ready to take on new challenges!

Hardhat vs Remix: Why Serious Solidity Developers Prefer Hardhat

If you're reading this, I'm assuming you've either used Remix before or at least heard of it. Remix is excellent for experimenting with Solidity in the browser. Still, if you're building production-ready smart contracts, you'll quickly run into its limits when you want to:

  • Work on larger projects

  • Use version control (Git)

  • Write automated tests

  • Script your deployments

  • Collaborate as real developers do
    That's where Hardhat comes in.

    ๐Ÿ’ก
    What is Hardhat? Hardhat is a local development environment for building, testing, and deploying Solidity smart contracts with professional workflows.

    Here's what Hardhat gives you that Remix doesn't:

    ๐Ÿงช Real Testing Support

    In Hardhat, you can write automated tests in JavaScript or TypeScript to verify your contract logic.

    Don't worry if this sounds new. We'll explain and write your first real tests later in the guide. This example shows what's possible.

    Here's a simple example of a test case:

it("should accept ETH deposits", async function () {
  await addr1.sendTransaction({
    to: tipJar.target,
    value: ethers.parseEther("0.01"),
  });

  const balance = await tipJar.getBalance();
  expect(balance).to.equal(ethers.parseEther("0.01"));
});

โœ… This test sends 0.01 ETH to the contract and verifies that the balance is updated correctly. When you run your tests, you'll see a similar result later in this guide.

๐Ÿ“ Project Structure That Scales

Hardhat encourages an organized project structure with separate contracts, scripts, and test folders. This approach is beneficial as it helps you build with real development workflows in mind, not just for quick experiments. It also makes your project more scalable and easier to manage as it grows in complexity.

๐Ÿงฑ Scripted Deployments

Instead of relying on a UI to deploy, Hardhat encourages a more professional approach to scripts. These reusable, version-controlled scripts align with how professional teams manage contracts.

๐Ÿ”Œ Plugins and Integrations

Hardhat supports many tools, such as Ethers.js, OpenZeppelin, Tenderly, The Graph, and Chainlink. It's flexible, extendable, and widely used in real projects.

But here's the important thing:

๐Ÿ’ก
This guide is designed for those who are starting from scratch and have not installed Node.js, Hardhat, or any other development tools.

I'll walk you through from absolute zero, including:

  • Installing the correct versions (so you don't get version mismatch errors)

  • Explaining what every command does

  • Breaking down what each file means and why it matters

You're in the right place if you've ever closed a Hardhat tutorial because it assumed too much.

๐Ÿ› ๏ธ Hardhat System Requirements and Setup Guide

Hardhat System Requirements and Setup Guide

Before executing any commands, ensure your system is configured correctly. Skipping these steps may lead to frustrating errors later. Hereโ€™s what you need and how to prepare everything.

๐Ÿ–ฅ๏ธ Your Terminal (Command Line)

๐Ÿ–ฅ๏ธ Your Terminal (Command Line)

๐Ÿ–ฅ๏ธ Your Terminal (Command Line)

The terminal is where you'll run every command during Solidity development. Whether you're on Mac, Windows, or Linux, you must get comfortable using it.

  • Mac: Use the built-in Terminal app.

  • Windows: Use Command Prompt, PowerShell, or Windows Terminal (recommended).

  • Linux: You already know your way around! ๐Ÿ˜Ž

โœ… Check that your terminal is responsive:

Open it and type this command:

echo Hello Hardhat

Your terminal will work fine if it prints Hello Hardhat back to you.

๐Ÿ’ป Node.js and npm

๐Ÿ’ป Node.js and npm

Hardhat runs on Node.js, so this part is not optional. You'll also install the necessary tools using npm (Node Package Manager).

โœ… Install Node.js:

Go to https://nodejs.org and download the LTS (Long-Term Support) version.

Avoid the "Current" version unless you know what you're doing, as it may cause compatibility issues.

๐Ÿ“ At the time of writing, the LTS versions are:

  • Node: v20.x.x

  • npm: v10.x.x

Hardhat supports Node.js versions from 18 to 22 and npm versions 8 and above.

โœ… Confirm installation:

Once installed, open your terminal and run:

node -v
npm -v

You should see version numbers like:

v22.16.0
10.9.2

If you see those, you're all set.

๐Ÿง  A Code Editor (I Recommend VS Code)

To write and manage your smart contracts, you'll need a code editor. Visual Studio Code is a great choice for beginners.

โœ… Download it: https://code.visualstudio.com

After installing, open VS Code and install the Solidity extension from the Extensions tab. This extension provides syntax highlighting, code suggestions, and error checking to make writing contracts easier.

๐ŸฆŠ MetaMask (For Testnet Deployment)

๐ŸฆŠ MetaMask (For Testnet Deployment)

If you plan to deploy contracts to a public testnet like Goerli or Sepolia, you'll need MetaMask.

Here's what to do:

  1. Install the MetaMask browser extension.

  2. Set up your wallet.

  3. Use a faucet to get free test ETH.

๐Ÿ’ก
A testnet is a safe blockchain version where you can practice deploying smart contracts using fake ETH.

It's optional at this stage, but useful when ready to go live.

โœ… Take a breather

Once you've installed these tools, you're in a great spot. You've completed a critical part of the setup. When ready, we'll walk you through creating your first Hardhat project.

Step 1: Install Hardhat and Set Up Your First Smart Contract Project

Now that your Solidity environment is ready, let's begin the straightforward process of creating your first Hardhat-powered smart contract project. This step will establish a basic folder structure that includes everything you need to write, compile, and deploy smart contracts.

๐Ÿ”“
Many tutorials rush through this setup, but weโ€™ll take our time and explain whatโ€™s happening at each step so you understand exactly what you're building. If you're new to using the terminal, donโ€™t worry. Iโ€™ll guide you through this process like a setup assistant.

This process is designed to work seamlessly on Mac, Linux, and Windows (using PowerShell). If you follow along exactly, you'll have a functioning local Solidity development setup, regardless of your operating system.

โš ๏ธ Important: As of Hardhat v2.24.2 and later, you should initialize a project using npx hardhat init. The older npx hardhat method is deprecated and will be removed in future versions. This guide uses the updated approach.

๐Ÿ“ 1. Create a New Project Folder

Choose a folder on your machine to store your smart contracts and project files.

For Mac/Linux:

mkdir my-first-hardhat
cd my-first-hardhat

For Windows (PowerShell):

mkdir my-first-hardhat
cd my-first-hardhat

This creates a new folder and changes your working directory to it.

๐Ÿงฑ 2. Initialize a Node Project

Hardhat is installed as a dependency in a Node.js project, so we must create a package.json file. Run the following command:

npm init -y

This sets up the project with default settings; you'll now have a package.json file.

โš™๏ธ 3. Install Hardhat

Next, install Hardhat locally by running:

npm install --save-dev hardhat

The --save-dev flag marks it as a dev dependency only needed during development.

๐Ÿš€ 4. Initialize the Project with npx hardhat init

Now that Hardhat is installed, run:

npx hardhat init

This is the new and recommended way to scaffold a Hardhat project.

You'll see a menu like this:

โœ” What do you want to do?
  - Create a JavaScript project
  - Create a TypeScript project
  - Create a TypeScript project (with Viem)
  - Create an empty hardhat.config.js
  - Quit

โœ… Choose: Create a JavaScript project

Hereโ€™s why weโ€™re picking this option:

- JavaScript is beginner-friendly and widely used.

- It integrates smoothly with Hardhat's sample tests and deployment scripts.

- You wonโ€™t have to worry about TypeScript configurations, types, or additional files.

Next, it will prompt you:

โœ” Project root: (your-folder-name)

โœ… Press Enter to use the current folder you are already in.

Then, youโ€™ll be asked:

  • Add a .gitignore โ†’ Yes

  • Install sample project dependencies โ†’ Yes (hit "Y")

Hardhat will install:

  • ethers

  • hardhat-toolbox

    Hardhat uses these main packages to deploy, test, and interact with Ethereum smart contracts. You might see some npm WARN messages or low-level vulnerabilities; this is normal and won't affect your ability to build. You can optionally run npm audit fix later if you wish.

๐Ÿ“ฆ What Youโ€™ll See in Your Project Folder

Once the setup is complete, you will find the following in your project folder:

  • Contracts/: Where your Solidity files go

  • Test/: Where tests will be located.

  • hardhat.config.js: The configuration file for your project.

  • .gitignore, README.md, and a few other basic files.

โœ… You are now set up with a real Solidity development environment.

In the next step, we will replace the sample contract with your own and deploy it locally.

Step 2: Writing Your First Contract in Hardhat

At this point, you should have a working Hardhat project with some sample code. Let's delete that sample code and write our simple contract.

We will start by creating a contract that allows people to send ETH into a tip jar and lets the owner withdraw it later. This contract is beginner-friendly but still teaches essential concepts such as payable, address, require, and state variables.

๐Ÿงน 1. Remove the Sample Contract

Hardhat generates a sample file called Greeter.sol. To remove it, follow these steps:

  1. Open your project folder in Visual Studio Code (VS Code):

    • Launch VS Code.

    • Go to File > Open Folder and select the my-first-hardhat folder.

  2. Navigate to:

    • contracts/Greeter.sol
  3. Delete the Greeter.sol file.

You may also want to delete the default test file:

  • test/sample-test.js

This will help you start fresh.

๐Ÿ“„ 2. Create a New Solidity File

Inside the contracts/ folder, create a new file named TipJar.sol. Paste the following code inside the file, which includes comments to help you understand each part:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18; // Tells Solidity which version you're using

contract TipJar {
    address public owner; // Stores the address of the contract owner

    constructor() {
        owner = msg.sender; // Sets the deployer as the owner
    }

    // Allows the contract to receive ETH directly
    receive() external payable {}

    // Returns the balance held in the contract
    function getBalance() public view returns (uint) {
        return address(this).balance;
    }

    // Allows only the owner to withdraw all the ETH
    function withdraw() public {
        require(msg.sender == owner, "Only the owner can withdraw");
        payable(owner).transfer(address(this).balance);
    }
}

What this contract does:

  • Accepts ETH from anyone

  • Lets the owner withdraw funds

  • Shows how much ETH is stored

โš™๏ธ 3. Compile Your Contract

Once you have written your contract, it's time to compile it so Hardhat can generate the necessary files for deployment and interaction.

Run the following command in your terminal:

npx hardhat compile

โœ… This command will:

  • Check your Solidity code for errors.

  • Compile it into bytecode and ABI(Application Binary Interface).

  • Save the output in the artifacts/ folder.

  • Store metadata in the cache/ folder.

๐Ÿ“ Whatโ€™s in the <artifacts/> folder?

The artifacts/ folder contains the compiled versions of your smart contracts. For each .sol file, you'll find a corresponding .json file that includes:

  • ABI (Application Binary Interface): needed to interact with the contract.

  • Bytecode: what gets deployed to the blockchain.

  • Metadata: includes compiler version, settings, etc.

Hardhat uses these files during deployment, testing, and console use.

๐Ÿ—ƒ๏ธ Whatโ€™s in the <cache/> folder?

The cache/ folder helps Hardhat track what has already been compiled. If your contract hasn't changed, Hardhat can skip recompilation to save time.

You don't need to manually edit this folder โ€” it's managed internally by Hardhat.

โœ… Successful Output

If everything is working correctly, you should see a message like:

Compiled 1 Solidity file successfully

โœ… Before vs After:

  • Before: You had a blank TipJar.sol file.

  • After compiling: You now have ABI, bytecode, and metadata in artifacts/.

    Your contract is ready for deployment.

๐ŸŽ‰ Congratulations!

You just wrote and compiled your first contract in Hardhat!

Once your contract is compiled, you can deploy it to a local Hardhat network and start interacting with it!

Step 3: Deploy the Contract Locally

Now that your contract is written and compiled, letโ€™s deploy it to a local blockchain using Hardhatโ€™s built-in network.

This wonโ€™t cost real ETH or require MetaMask. It all runs on your machine.

๐Ÿงพ 1. Create a Deploy Script

Inside the scripts/ folder, create a new file named deploy.js.

Paste the following code into it:

 const hre = require("hardhat");

async function main() {
  const TipJar = await hre.ethers.getContractFactory("TipJar");

  // Deploy the contract
  const tipJar = await TipJar.deploy();

  // Wait for the deployment transaction to be mined
  await tipJar.waitForDeployment();

  console.log(`Contract deployed to: ${tipJar.target}`);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

โœ… This script:

  • Compiles your contract if needed

  • Deploys it to the local Hardhat blockchain

  • Logs the contract address

๐Ÿงช 2. Run a Local Node + Deploy

In your terminal, use this command:

npx hardhat run scripts/deploy.js

You should see output like:

Contract deployed to: 0xYourContractAddressHere

Thatโ€™s it! Your contract is now deployed locally. No wallet, no gas, no real blockchain needed.

Next, weโ€™ll show you how to interact with your deployed contract using the console.

Step 4: Interact With the Contract Using the Console

Now that your contract is deployed locally, let's interact with it using Hardhat's built-in JavaScript console.

This lets you test and call your contractโ€™s functions directly, without needing a front-end or UI.

๐Ÿ–ฅ๏ธ 1. Start the Local Hardhat Network

In your terminal, run:

npx hardhat node

This will:

  • Start a local Ethereum blockchain at http://127.0.0.1:8545

  • Create 20 test accounts with ETH

  • Keep running as a background blockchain for testing

    ๐ŸŸก
    Leave this terminal window running. Do not close it.

To open a second terminal:

  • Mac: Press Cmd + T in Terminal or open a new window

  • Windows (PowerShell or Terminal): Press Ctrl + Shift + T or click the dropdown arrow โ†’ "New Tab"

  • Linux: Press Ctrl + Shift + T

๐Ÿ” 2. Deploy to the Local Node (Not In-Memory)

In the second terminal, go to your project folder again:

cd path/to/your/my-first-hardhat

Then run this command to deploy your contract to the running node:

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

Youโ€™ll see output like:

Contract deployed to: 0xYourContractAddressHere

โœ… Copy this address โ€” weโ€™ll use it in the next step.

๐Ÿ’ฌ 3. Open the Hardhat Console

Still in your second terminal, run:

npx hardhat console --network localhost

This opens an interactive JavaScript console connected to your local blockchain.

๐Ÿงช 4. Interact With Your Deployed Contract

Now letโ€™s load the contract inside the console. Paste and run each line one at a time, pressing Enter after each line.

๐Ÿšจ
If you see undefined, thatโ€™s normalโ€”it just means the console didnโ€™t print a return value. The command still worked.
const tipJarFactory = await ethers.getContractFactory("TipJar")

Youโ€™ll likely see:

undefined

Check if it worked by running:

tipJarFactory

This should return a ContractFactory object.

Attach to the deployed contract:

const tipJar = await tipJarFactory.attach("0xYourContractAddressHere")

Replace the address with your actual deployed address.

Confirm it's loaded:

tipJar.target

This should return the address again.

โœ… Now test your contract:

Check the balance:

await tipJar.getBalance()

Youโ€™ll get:

0n

That n means the value is a BigInt. Solidity values in ethers.js v6+ come as BigInts, not regular numbers.

Send a tip:

const [signer] = await ethers.getSigners()
await signer.sendTransaction({
  to: tipJar.target,
  value: ethers.parseEther("0.01")
})

Check the balance again:

await tipJar.getBalance()

Youโ€™ll see:

10000000000000000n

Which is 0.01 ETH in wei.

Withdraw as the owner:

await tipJar.withdraw()

Youโ€™ll see a long ContractTransactionResponse object confirming the transaction was successful.

โœ… You've now:

- Simulated tipping

- Checked the on-chain balance

- Withdrawn ETH โ€” all locally, with no wallet required!

Step 5: Write Tests for Your Smart Contract

 Step 5: Write Tests for Your Smart Contract

If you were building a car, would you drive it at 200 km/h without testing the brakes? Exactly.

Smart contracts handle real money. Once deployed, they're immutable, meaning one bug could cost you or your users thousands.

Testing helps you:

  • Catch logic errors before they go live

  • Simulate how your contract behaves with real transactions

  • Gain confidence that your code is solid

Let's write a basic test for your TipJar contract to check two core behaviors:

  1. It accepts tips

  2. It allows the owner to withdraw

๐Ÿงช 1. Create the Test File

In your Hardhat project, go to the test/ folder and create:

test/tipjar-test.js

โœ๏ธ 2. Add This Code (With Comments)

// Load Chai for assertions and Hardhat's ethers for contract interaction
const { expect } = require("chai")
const { ethers } = require("hardhat")

// Group our TipJar tests together
describe("TipJar", function () {
  let TipJar, tipJar, owner, addr1

  // This runs before each test to deploy a fresh contract
  beforeEach(async function () {
    TipJar = await ethers.getContractFactory("TipJar") // Load the contract factory
    ;[owner, addr1] = await ethers.getSigners()        // Get two test accounts
    tipJar = await TipJar.deploy()                     // Deploy a new contract
    await tipJar.waitForDeployment()                   // Wait for full deployment
  })

  // โœ… Test: Can people send ETH to the contract?
  it("should accept ETH deposits", async function () {
    await addr1.sendTransaction({
      to: tipJar.target, // Send 0.01 ETH to the TipJar contract
      value: ethers.parseEther("0.01"),
    })

    const balance = await tipJar.getBalance() // Call the getBalance() function
    expect(balance).to.equal(ethers.parseEther("0.01"))
  })

  // โœ… Test: Can the owner withdraw funds?
  it("should allow owner to withdraw", async function () {
    // First, send 0.01 ETH to the contract
    await addr1.sendTransaction({
      to: tipJar.target,
      value: ethers.parseEther("0.01"),
    })

    await tipJar.withdraw() // Owner calls withdraw()

    const balance = await tipJar.getBalance()
    expect(balance).to.equal(0n) // Balance should be 0
  })
})

๐Ÿงช 3. Run the Tests

๐Ÿšจ Important: If you're still inside the Hardhat console (from the second terminal where you interacted with the contract), exit it first:

.exit

Then, hit Enter to return to your standard terminal prompt.

Now, from your project directory (still in that terminal), run your tests:

npx hardhat test

You should see something like:

TipJar
  โœ” should accept ETH deposits
  โœ” should allow owner to withdraw

โœ… Thatโ€™s it! Youโ€™ve tested your first real smart contract.

Step 6: Deploy to a Public Testnet With MetaMask (With No Confusion)

Step 6: Deploy to a Public Testnet With MetaMask (With No Confusion)

So far, you've deployed and tested your contract locally.

Great job! Now it's time to put it somewhere others can see it, like the Sepolia testnet, using MetaMask, Alchemy, and Hardhat.

๐Ÿ”‘ Prerequisites

Before deploying to Sepolia, you must gather some essential tools and details. Think of this as preparing your passport, ticket, and wallet before boarding a flight. Once all of this is ready, your deployment will be smooth.

๐Ÿงน What You Need to Deploy to a Public Testnet With MetaMask

  1. MetaMask extension installed in your browser โ€“ Get it here

  2. A MetaMask wallet was created earlier(save your secret phrase securely)

  3. A Sepolia wallet address in MetaMask (select Sepolia network)

  4. A free Alchemy account โ€“ Sign up at alchemy.com

๐Ÿ’กWhere to Find Your Metamask Private Key

To deploy your project, you need the private key from the specific MetaMask account youโ€™ll be using. Please note that this differs from your Secret Recovery Phrase; it is the individual account's private key.

  1. Click the MetaMask extension icon in your browser toolbar.

  2. Select the account (ensure Sepolia is selected).

  3. Click the three dots โ†’ Account details โ†’ Export Private Key.

  4. Enter your MetaMask password to reveal the key.

  5. Copy the private key (keep it safe!).

๐Ÿšจ
This key goes into your .env file. Please doย notย share it or commit it to GitHub.

๐Ÿ”ง Where to Get Your Sepolia RPC URL in Alchemy

  1. Go to the Alchemy Dashboard

  2. Click Create App

  3. Name it e.g. hardhat-sepolia

  4. Choose Ethereum as the chain.

  5. After creation, select Sepolia Network โ†’ Copy the Network URL

Example:

https://eth-sepolia.g.alchemy.com/v2/YourApiKeyHere

๐Ÿ’ธ How to Get Free Sepolia ETH (No Mainnet Required)

Use the Google Cloud Faucet to avoid mainnet ETH requirements:

  • Paste your MetaMask extension Sepolia address

  • Complete CAPTCHA

  • Receive 0.5 Sepolia ETH instantly

๐Ÿš€ Deployment Guide to Deploy to a Public Testnet With MetaMask

Now that your environment is ready, you're about to deploy your contract to a live blockchain environment with which others can see and interact.

๐Ÿ› ๏ธ 1. Install dotenv

Before connecting to Sepolia, we need a way to safely store and load your private key and RPC URL inside the project. This is where the dotenv package comes in. It lets you keep sensitive info in a separate file so you don't hardcode anything sensitive into your scripts.

npm install dotenv

๐Ÿ“ 2. Create a .env File

In your project root, create .env:

PRIVATE_KEY=your_metamask_private_key_here
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YourApiKeyHere
๐Ÿ”Š
Add .env to .gitignore to keep secrets safe out of version control.
๐Ÿ”Š
Hardhat does not automatically create .env file. To prevent leaks, you must create it manually and ensure it's excluded from version control.

โš™๏ธ 3. Update hardhat.config.js

Replace the contents with:

// hardhat.config.js

// 1. Load environment variables
require("dotenv").config();
// 2. Load the Hardhat Toolbox plugin (injects hre.ethers, tests, etc.)
require("@nomicfoundation/hardhat-toolbox");

const { PRIVATE_KEY, SEPOLIA_RPC_URL } = process.env;

module.exports = {
  solidity: "0.8.21",
  networks: {
    sepolia: {
      url: SEPOLIA_RPC_URL,     // comes from .env
      accounts: [PRIVATE_KEY],  // comes from .env
    },
  },
  etherscan: {
    apiKey: "", // Optional: leave blank or set via env
  },
};

This configuration ensures Hardhat knows how to connect to Sepolia using the credentials and endpoint stored in your .env file.

๐Ÿ“œ 4. Update scripts/deploy.js

// scripts/deploy.js
const hre = require("hardhat");

async function main() {
  // Get the contract factory
  const TipJar = await hre.ethers.getContractFactory("TipJar");

  // Deploy the contract
  const tipJar = await TipJar.deploy();

  // Wait for deployment to be confirmed (Ethers v6+ method)
  await tipJar.waitForDeployment();

  // Log the deployed contract address
  console.log("โœ… TipJar deployed to:", tipJar.target);
}

main().catch((error) => {
  console.error("โŒ Deployment error:", error);
  process.exit(1);
});

This is a basic deployment script. You can reuse this pattern for other contracts by updating the name passed to getContractFactory.

๐Ÿš€ 5. Deploy to Sepolia

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

Expected output:

Downloading compiler...
Compiled successfully
โœ… TipJar deployed to: 0xYourDeployedAddressHere

Double-check your values, network name, and script path if you encounter any errors.

๐ŸŽ‰ Your contract is now live on Sepolia! View mine on Sepolia Etherscan.

Step 7: Verify Your Contract on Etherscan

Verifying your contract source code on Etherscan adds trust and transparency. Others can read your code, see comments, and confirm your contractโ€™s behavior.

1. Get an Etherscan API Key

  1. Log in to Etherscan and navigate to the API Dashboard.

  2. Click Add in API Key Section, name it (e.g., TipJarSepolia), and click Create.

  3. Copy the generated API key.

2. Store the Key in .env

Open your .env file and add:

ETHERSCAN_API_KEY=YourEtherscanApiKeyHere
๐Ÿ”
Make sure .env is in .gitignore to keep your key private.

3. Configure hardhat.config.js

Ensure you have the Hardhat Toolbox plugin loaded:

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

Then add or update the etherscan section:

module.exports = {
  solidity: "0.8.21",
  networks: { /* ... */ },
  etherscan: {
    apiKey: process.env.ETHERSCAN_API_KEY,
  },
}

4. Run the Verification Task

In your terminal, run:

npx hardhat verify --network sepolia <DEPLOYED_CONTRACT_ADDRESS>

Replace <DEPLOYED_CONTRACT_ADDRESS> with your actual address.

5. View Your Example

You can see the verified source for our demo here:

Awesome! Your contract is now verified; you have a working example to reference.

Step 8: Push Your Project to GitHub (Using GitHub Desktop)

Git on the command line can be tricky at first. If you prefer a graphical interface, GitHub Desktop pushes your project to GitHub as easily as a few clicks.

๐Ÿงฉ What You Need

  1. GitHub Desktop installed โ€” Download here

  2. GitHub account โ€” if you havenโ€™t already, sign up at github.com

๐Ÿ“ฆ 1. Open Your Project in GitHub Desktop

  1. Launch GitHub Desktop.

  2. Click File โ†’ Add Local Repositoryโ€ฆ

  3. Browse to your project folder and click Add Repository.

โœ๏ธ 2. Create a .gitignore File (Once Only)

If you havenโ€™t already, add a .gitignore in your project root with:

node_modules/
.env
cache/
artifacts/

This prevents unnecessary or sensitive files from being pushed.

๐Ÿ“‚ 3. Commit Your Changes

  1. In GitHub Desktop, youโ€™ll see all uncommitted changes.

  2. In the Summary box, type Initial commit: Hardhat TipJar project.

  3. Click Commit to main.

๐ŸŒ 4. Publish Repository to GitHub

  1. Click Publish repository in the top toolbar.

  2. Name the repo hardhat-tipjar (or customize). Add a description (optional), and set it to Public.

  3. Click Publish Repository.

๐Ÿš€ 5. Verify on GitHub

Navigate to your GitHub profile or directly to the repository URL

Youโ€™ll see your files, commit history, and have a link you can share with others.

Next, now that your code is on GitHub, anyone can clone or fork it to get started quickly. Feel free to explore more GitHub Desktop features like branching, merging, and pull requests!

๐Ÿ”ง Common Smart Contract Beginner Mistakes to Avoid

These are mistakes I made, so you donโ€™t have to. Learn from them to avoid painful debugging sessions and wasted time.

โŒ Skipping Node.js setup
Always install the Long-Term Support (LTS) version of Node.js and verify it's installed with:

node -v
npm -v

โŒ Using the wrong Hardhat init command
Use:

npx hardhat init

Avoid using:

npx hardhat

Which runs the interactive prompt, but does not initialize a project properly in every case.

โŒ Forgetting to ignore .env files
Never commit your .env file. Add it to .gitignore immediately:

.env

This file contains sensitive keys and should never be pushed to version control.

โŒ Deploying without starting a local node
When deploying locally, always begin the local blockchain first:

npx hardhat node

Otherwise, your deployment will fail to connect to any running chain.

โŒ Rushing past errors
When errors appear, take your time reading the stack trace and messages carefully. Often, the solution is already hinted at in the log.

What You Built

You made it. Not only did you follow through, but you also built something real.

Here's a recap of what you accomplished:

  • โœ… Wrote your first Solidity smart contract (TipJar)

  • โœ… Tested it locally using Hardhat's development environment

  • โœ… Deployed it to the Sepolia public testnet with MetaMask and Alchemy

  • โœ… Used environment variables to keep sensitive data safe

  • โœ… (Optional) Verified the source code on Etherscan

  • โœ… Published your project to GitHub for others to see

What You Can Do Next

This project is your launchpad. From here, you can:

  • Expand the contract (add tipping limits, events, or withdrawal logic)

  • Connect your contract to a frontend using HTML/JavaScript or React

  • Explore Hardhat plugins for testing, deployment, and verification

  • Build more advanced projects like:

    • Multi-send wallets

    • Voting dApps

    • NFT collections

Final Advice

  • Keep this project saved. It's your Web3 "Hello, world."

  • Donโ€™t be afraid to tweak, break, and fix it. Thatโ€™s how you grow.

  • Start putting your work out there:

    • Push to GitHub

    • Write blog posts

    • Share on X (Twitter) or LinkedIn

Your goal might be to freelance, land a job, or launch your dApp. Whatever it is, the most important thing is that youโ€™ve built and finished something real. Thatโ€™s how confidence and momentum begin. That puts you ahead of most.

Let's keep building. โœจ

1
Subscribe to my newsletter

Read articles from Peace Aisosa Osarenren directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Peace Aisosa Osarenren
Peace Aisosa Osarenren