Deploy Smart Contracts Locally Using Hardhat : If you’ve just written your first smart contract, the next exciting step is bringing it to life — deploying it to a blockchain. But here’s the thing: we don’t always want to spend real ETH or wait for slow testnets just to see our contracts in action. That’s where the Hardhat Network comes in.
Table of Contents
The Hardhat Network is like having your own mini Ethereum blockchain running right on your computer. It’s instant, free, and perfect for rapid testing. Think of it as your “private crypto playground” where you can deploy contracts, test transactions, and even simulate mining — without worrying about gas fees or network delays.
In this guide, I’ll walk you through deploying smart contracts locally using Hardhat Network. We’ll launch a local blockchain node, check out our pre-funded accounts, write a simple deployment script, interact with our contracts through the console, and monitor balances/state changes in real time.
By the end of this tutorial, you’ll be confident enough to deploy and test any Solidity contract locally — and you’ll know exactly what’s happening under the hood.
Step 1: Setting Up Your Hardhat Project

Before we dive into deploying contracts, let’s make sure we have Hardhat set up.
If you haven’t already, create a fresh project:
mkdir hardhat-deploy-tutorial
cd hardhat-deploy-tutorial
npm init -y
npm install --save-dev hardhat
npx hardhat
When prompted, choose “Create a JavaScript project” (or TypeScript if you prefer). Hardhat will create a basic structure for you.
Step 2: Launching the Hardhat Network
The Hardhat Network runs automatically when you deploy or test, but you can also start it as a standalone local blockchain node.
Run:
npx hardhat node
You’ll see something like this in your terminal:
Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/
Accounts
========
0x1234... (10000 ETH)
0x5678... (10000 ETH)
...
What’s Happening Here?
- Hardhat spins up a blockchain locally, running on your machine.
- You get 20 test accounts, each preloaded with 10,000 ETH (fake ETH for testing).
- The network mines instantly, so transactions confirm immediately.
This is perfect for testing because you can:
- Deploy contracts instantly
- Debug transactions without spending real ETH
- Simulate different wallet balances and interactions
Step 3: Understanding Hardhat Accounts and Wallets

Hardhat gives you accounts in two forms:
- Private Keys – You can import these into MetaMask for local testing.
- Signer Objects – In scripts, these are
ethers.js
objects that represent wallets.
To view accounts, check your Hardhat node terminal output. You’ll see addresses and private keys like this:
Account #0: 0x1234...
Private Key: 0xabcdef123...
💡 Pro Tip: Import one of these private keys into MetaMask, and connect it to “Localhost 8545” network — you’ll see the 10,000 ETH balance there.
Step 4: Writing a Deployment Script
Let’s create a simple deployment script for our smart contract in Solidity.
We’ll use a SimpleStorage.sol example:
contracts/SimpleStorage.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
contract SimpleStorage {
uint256 public data;
function set(uint256 _data) public {
data = _data;
}
}
Now create the deployment script:
scripts/deploy.js
const hre = require("hardhat");
async function main() {
const SimpleStorage = await hre.ethers.getContractFactory("SimpleStorage");
const simpleStorage = await SimpleStorage.deploy();
await simpleStorage.deployed();
console.log(`SimpleStorage deployed to: ${simpleStorage.address}`);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Step 5: Deploy Smart Contracts Locally Using Hardhat

Make sure your local Hardhat node is running:
npx hardhat node
In a separate terminal, run:
npx hardhat run scripts/deploy.js --network localhost
You’ll see:
SimpleStorage deployed to: 0xABC123...
What Just Happened?
- Your script connected to the local blockchain at
localhost:8545
. - It compiled the contract, deployed it, and gave you an address.
- The contract is now live on your private blockchain.
Step 6: Interacting with the Contract via Console
Hardhat has a built-in console that lets you interact with contracts easily.
Run:
npx hardhat console --network localhost
Inside the console:
const SimpleStorage = await ethers.getContractFactory("SimpleStorage");
const simpleStorage = await SimpleStorage.attach("0xABC123..."); // contract address
await simpleStorage.set(42);
console.log((await simpleStorage.data()).toString()); // "42"
You just called a function on your deployed contract and read the stored value — instantly.
Step 7: Checking Balances and State using Hardhat

You can check wallet balances locally using ethers.js:
const [owner] = await ethers.getSigners();
console.log(ethers.utils.formatEther(await owner.getBalance()));
Because this is a local blockchain:
- Gas fees are deducted but instantly refunded (net cost = zero).
- You can reset everything anytime by restarting the node.
Step 8: Testing in Real Time
Let’s test a full transaction:
- Deploy contract
- Set value to 100
- Retrieve value
You’ll see immediate results without waiting for mining or confirmations — this is why local development is so much faster.
Step 9: Why Local Deployment Matters
Deploying smart contracts locally is more than just a convenience — it’s essential for:
- Fast debugging: No network delays.
- Cost efficiency: No real ETH needed.
- Complete control: You can reset or reconfigure anytime.
- Automated testing: Perfect for CI/CD pipelines.
It also prepares you for deploying on testnets/mainnet because you’re already used to writing deployment scripts and interacting programmatically.
Common Issues & Fixes
- Contract not found: Make sure it’s compiled (
npx hardhat compile
). - Wrong network: Double-check
--network localhost
flag. - Address mismatch: If you restart the node, contracts get new addresses — redeploy before interacting.
Best Practices for Local Deployment
- Always keep deployment scripts modular — easy to reuse for different networks.
- Store contract addresses in a
.json
file for easy reference. - Use
.env
files for private keys if connecting external wallets. - Integrate with Hardhat’s testing framework for automated checks.
The Hardhat Network is one of the most powerful tools in a blockchain developer’s toolkit. It allows you to deploy smart contracts locally, test interactions instantly, and debug without burning real ETH.
In this tutorial, we covered:
- Launching a local blockchain with Hardhat
- Exploring pre-funded accounts and wallets
- Writing and running deployment scripts
- Using the console to interact with contracts
- Checking balances and verifying state changes
With this knowledge, you’re now ready to confidently test any smart contract in a safe, controlled environment before deploying it to a live network.