Hello! Welcome back to your journey into blockchain development.
In our last lesson, you successfully set up a professional development environment with Hardhat and learned to use its core commands. We ended by running npx hardhat node and saw it generate a list of pre-funded Ethereum accounts.
Today, we will connect those local accounts to your MetaMask wallet. This is a vital step that allows you to "become" a user on your private blockchain, enabling you to test your smart contracts from a user's perspective. Your experience as a consultant for investment management software gives you a keen sense of the importance of user roles and permissions; think of this as setting up your first 'test user' in the system.
By the end of this lesson, you will be able to manage accounts on both your local Hardhat network and public testnets, a fundamental skill for any blockchain developer.
1. Hardhat's Development Accounts
When you run npx hardhat node, Hardhat spins up a local blockchain and generates a set of deterministic accounts for testing. Each account has a public address, a private key, and is pre-filled with test ETH.
Let's start the node again. Open your terminal in your project directory and run:
npx hardhat node
You will see output similar to the image below. Keep this terminal window open for the duration of the lesson.

The private key is the single most important piece of information; it grants complete control over an account. The address is derived from it and is safe to share publicly.
To prepare for the next step, let's follow the instructions from the article below to copy the private key of the first account.
How to Build a React Dapp with Hardhat and MetaMask
This article provides a clear walkthrough of setting up a development environment. We'll focus on the part that deals with the accounts generated by Hardhat.
Please read the section under the heading 'CLI Tools & Hardhat'. You have already completed most of these steps in the previous lesson. Focus on the final part where it discusses the output of the yarn hardhat node command (which is equivalent to npx hardhat node). Follow the instruction to copy the private key for Account #0 and paste it into a temporary text file. You will need it shortly.
2. Connecting MetaMask to Your Local Network
By default, MetaMask is configured to connect to the Ethereum Mainnet and several public testnets. To interact with the local blockchain running on your machine, you must manually add it as a custom network.
This requires two pieces of information from the Hardhat node's startup message:
- RPC URL: The address of the node. For Hardhat, this is typically
http://127.0.0.1:8545. - Chain ID: A unique identifier for the network. Hardhat uses
31337.
The following video demonstrates how to add a custom network in MetaMask. Although the video uses Ganache, another development tool, the procedure is identical for Hardhat.
Connect Metamask to Ganache (localhost) for web3 development
This video provides a clear, step-by-step visual guide on adding a new local network to MetaMask.
Watch the segment from 01:54 to 03:19. Follow the steps to add a new network in MetaMask. Use the following details for your Hardhat network: Network Name: Hardhat New RPC URL: http://127.0.0.1:8545 Chain ID: 31337 Currency Symbol: ETH (The video uses a different Chain ID and RPC port for Ganache; be sure to use the values listed above for Hardhat).
After you've added the network, your MetaMask should be connected to "Hardhat" but will show a new, empty account. In the next step, we'll import one of the funded accounts.
3. Importing a Hardhat Account into MetaMask
Now we'll use the private key you copied earlier to import one of Hardhat's pre-funded accounts into MetaMask. This will give you control over that account and its 10,000 test ETH.
How to Build a React Dapp with Hardhat and MetaMask
We'll return to the Web3 University article, which provides excellent written instructions for importing an account.
Read the part of the article under the subheading 'MetaMask Installation & Configuration'. Focus specifically on the final steps where it describes how to import an account using a private key. Follow these instructions to import the Hardhat account for which you copied the private key.
For a visual guide on the import process, you can watch the next segment of the video from earlier.
Connect Metamask to Ganache (localhost) for web3 development
This clip demonstrates the 'Import Account' feature in MetaMask.
Watch from 03:19 to 04:45. The video shows how to paste a private key to import a Ganache account. The steps are exactly the same for importing your Hardhat account. After importing, you can also follow the instructions to rename the account to something memorable, like Hardhat Account 0.
Once imported, you should see the account in MetaMask with a balance of 10,000 ETH. Congratulations! You now have a funded account ready for development and testing on your local blockchain.
4. A Critical Concept: Network-Specific Balances
It is crucial to understand that your new Hardhat Account 0 and its 10,000 ETH balance only exist on your local Hardhat network. If you switch MetaMask to another network, like Ethereum Mainnet, you will see that this account has a balance of 0 ETH.
This separation is fundamental to blockchain technology and a key safety feature. Your development activity and test funds are completely isolated from real-world assets.
Connect Metamask to Ganache (localhost) for web3 development
This short clip clearly illustrates how account balances are tied to the specific network you are connected to.
Watch from 05:20 to 05:54. The video demonstrates switching between a local network and a public testnet (Rinkeby, which is now deprecated, but the concept is the same). Notice how the balance of the imported account changes, reinforcing that funds are not shared across networks.
This is also why it's a critical security practice to use separate wallets (i.e., separate MetaMask seed phrases) for development and for holding real assets, a best practice recommended in the official MetaMask documentation.
5. Developer Pro-Tip: Handling Nonce Resets
When you stop and restart your npx hardhat node, the entire blockchain state is wiped and recreated. This means all accounts go back to a transaction count (or nonce) of 0. However, MetaMask remembers the previous nonce, which can cause new transactions to get stuck or fail.
This is a common point of frustration for new developers. Fortunately, there is a simple fix.
The official MetaMask documentation explains this issue and provides the solution.
Read the section titled 'Reset your local nonce calculation'. This explains why restarting your development network can confuse MetaMask. Follow the instructions to find the 'Reset account' button in Settings > Advanced. You don't need to click it now, but remember its location. You will use it whenever your transactions seem stuck after restarting your Hardhat node.
Conclusion
In this lesson, you bridged the crucial gap between your local development environment and a user-facing wallet. This practical skill is essential for testing any application you build.
You have learned to:
- Connect MetaMask to a local Hardhat blockchain node.
- Import a pre-funded development account into MetaMask using its private key.
- Recognize that account balances are network-specific.
- Reset your MetaMask account state to resolve nonce issues after restarting your local node.
You are now fully equipped to interact with your local development environment. In the next lesson, we will move from the local environment to a public testnet. You will acquire test ETH from a faucet, send a transaction, and learn how to inspect it on a public block explorer, bringing you one step closer to deploying contracts in a live setting.