Techniques for Developing Web3 Applications Using Hardhat
2025-12-25 06:03
Blockchain
Crypto Tutorial
Ethereum
Web 3.0
Web3 wallet
Article Rating : 3.5
131 ratings
Discover how to create Web3 apps using Hardhat with this comprehensive, step-by-step guide. You’ll cover everything from setting up your local environment to integrating crypto wallets and deploying smart contracts. This guide is perfect for both beginner and intermediate Web3 developers seeking a deeper grasp of technologies like React and Typescript. It follows best practices for modern DApp development.

# How to Build a React Dapp with Hardhat and a Crypto Wallet
## Prerequisites
This guide assumes you have a basic understanding of using the command-line terminal, Node.js, GitHub, and the git CLI. You’ll need this foundational knowledge to follow the comprehensive Dapp development steps outlined below.
## Disclaimer
This article is for educational purposes only. Any use of crypto wallet browser extensions described here is strictly for development and testing. You will not interact with real funds or live blockchain networks—only a local test network will be used. As such, security best practices are relaxed in this context.
For any testing, experimentation, or development work, always install the crypto wallet extension in a separate browser from the one you use for real funds or live networks. This precaution helps you avoid accidentally using test accounts on a mainnet. If you plan to use a crypto wallet extension with real funds on a live network, conduct your own research on secure usage, as blockchain security is a complex subject beyond this article’s scope.
## Why Another 'Build a Dapp' Article?
Many Dapp development guides are available online. However, even among high-quality articles, some are outdated, and none cover all the components found in modern [DeFi](https://dex.gate.com/crypto-wiki/article/understanding-defi-a-beginner-s-guide-20251223) projects in one place.
This guide brings together the following technologies for a modern web3 development stack:
- Hardhat as the Ethereum development framework
- Browser-based crypto wallet
- ethers.js
- React
- Typescript
- The web3-react npm package
- Development tools like eslint and prettier
The largest DeFi protocols use all these technologies today. Don’t worry if you’re new to any of them—they’ll be explained in detail as you go.
## What You’ll Build/Run
Your goal is to build a Dapp with a user interface that fully demonstrates blockchain functionality. This Dapp is intentionally simple, using a “Greeter” smart contract that lets you read and update a greeting on your local blockchain. The Greeter contract is a basic starter contract auto-generated by Hardhat when you initialize a new project.
Your Dapp will demonstrate these core features:
1. Connecting the Dapp to a blockchain using a browser-based crypto wallet
2. Reading account data from the blockchain via your wallet
3. Cryptographically signing digital messages with your wallet
4. Deploying a new smart contract instance using your wallet
5. Reading and writing data to and from the deployed smart contract
## Tools You’ll Use
Hardhat is a robust tool suite for developers to run a local Ethereum development blockchain, write and debug Solidity smart contracts, and run tests—all without touching the live Ethereum network. You’ll use Hardhat to spin up your own local Ethereum testnet.
A browser-based crypto wallet is a browser extension that supports multiple Ethereum networks and enables users to interact with those networks. You’ll use it to bridge your Dapp and the local Hardhat node.
You’ll also use the git CLI to clone sample code from GitHub, and install node and yarn to build, compile, and run both your smart contracts and Dapp frontend. All CLI tools will be accessed via the Terminal.
## CLI Tools & Hardhat
First, install the required tools and obtain the sample code. You’ll need node, npm (Node.js), and yarn installed. With those in place, create a new Node.js/Hardhat project.
Open your Terminal, navigate to your development directory, and run the following commands:
```
npm install --global yarn
git clone [repository]
cd hardhat-ethers-react-ts-starter
yarn && cd frontend && yarn && cd ..
yarn hardhat compile
yarn hardhat node
```
The final `yarn hardhat node` step is critical—you need the local Hardhat network running before configuring your crypto wallet extension for development.
When Hardhat is running, you’ll see your local Ethereum network active on port 8545, with several pre-funded test accounts, their public addresses, and private keys—each loaded with 10,000 test ETH.
Copy Account #0’s private key and save it in your text editor. You’ll use it when setting up your wallet.
## Crypto Wallet Installation & Configuration
Go to your crypto wallet provider’s site and install the browser extension. Click “Download” and follow the steps to add the wallet extension to your browser.
After installation, the extension will prompt you with a “Getting Started” screen. Click “Get Started” and follow the instructions for your wallet’s initial setup.
Next, adjust some wallet settings. Click “Ethereum Mainnet” in the top right (next to the circular identicon) to open the network dropdown. Then click “Show/hide” test networks, which opens the “Advanced” settings page.
Enable “Show test networks” and also turn on “Customize transaction nonce.” While not strictly required, customizing the transaction nonce is very helpful during contract development.
The account nonce counts transactions sent from an account, ensuring transactions are only processed once. For contract accounts, it tracks the number of contracts created. Customizing the nonce is useful because restarting your Hardhat node resets the nonce to 0, but your wallet may remember the previous value.
Next, update the “Chain Id” for Localhost:8545 to match your Hardhat network. In Settings, click Networks, then select Localhost:8545. Change the Chain ID to 31337—the value used by Hardhat. The node must be running for this change to succeed.
Save your changes. Now, Localhost in your wallet is the selected network and is properly configured for your Hardhat network.
Finally, import your Hardhat test account into the wallet. Exit the Settings menu, click the identicon, and select “Import Account.”
Paste the private key for Account #0 (from earlier) after selecting “Private Key” in the dialog, then click “Import Account.”
Never use this test account for real funds or on mainnet. It’s only for testing and development on local or test networks.
Once imported, your wallet will show as connected to Localhost:8545. The newly imported account (Account 2) is selected, and it holds 10,000 test ETH.
## Connecting the Crypto Wallet to the Dapp
The Greeter Dapp frontend is built in React and interacts with your local blockchain and smart contract (contracts/Greeter.sol, a simple starter contract from Hardhat).
To connect, start your frontend web server. Open Terminal, navigate to your project directory, and run:
```
cd frontend
yarn start
```
If all goes well, a browser window will open at localhost:3000. If not, open your browser and enter the URL manually.
The Dapp will show your wallet isn’t connected yet. Click “Connect” and choose Account 2 (the account you imported) from the wallet dialog.
Click “Next,” then “Connect” in the wallet dialog. Your wallet is now connected to the Greeter Dapp frontend, ready to interact with the Greeter.sol contract.
## Using the Crypto Wallet to Cryptographically Sign Digital Messages
Cryptographic message signing is fundamental to blockchain. Think of it like writing a letter and signing your name—the signature lets the recipient verify the message is truly from you. Click “Sign Message” in your Dapp and a wallet dialog will prompt you.
Note two things:
1. The wallet asks for a Signature Request
2. The message is just a “wave” emoji (hardcoded in the frontend for demonstration purposes)
Click “Sign” in your wallet dialog. The Dapp will respond, confirming the wallet account successfully signed the message.
Signing a message is not the same as sending a blockchain transaction—it requires no gas and doesn’t alter blockchain state. Check the UI: Next Nonce remains 0 since no transactions have been made.
## Deploying a Greeter Dapp Instance
Deploy a Greeter.sol contract instance to your local blockchain before interacting with it. Click “Deploy Greeter Contract” in the UI. If your wallet nonce isn’t 0, set it to 0 (this should be your first transaction).
Deploying the contract creates a blockchain transaction, consumes (test) gas, and increments your nonce from 0 to 1.
Click “Confirm” in your wallet dialog. Wait for deployment; an alert will show your contract’s address. Click “Ok” and return to the UI.
Your account balance will decrease slightly due to gas spent, and your Next [Nonce](https://dex.gate.com/crypto-wiki/article/understanding-nonce-in-blockchain-technology-a-key-concept-explained-20251129) increments by one (you’ve made your first transaction).
The UI displays details for the deployed contract: the instance address and its state (the greeting), which by default is “Hello, Hardhat!”
## Writing to Your Local Ethereum Blockchain
You wrote to the blockchain when deploying Greeter, but let’s explicitly change the contract’s greeting. Enter a new greeting in the “Set new greeting” field and click “Submit”—the wallet dialog will appear again.
Click “Confirm” and wait for the updated greeting to be written on-chain. If successful, a pop-up confirms the transaction. Click “Ok” and review the UI.
The greeting updates, your account balance drops slightly, and Next Nonce is now 2. Everything is working as expected!
Caveat: Restarting the Hardhat node during development can cause wallet cache data to get out of sync with the actual blockchain state. If this happens, switch the wallet from Localhost:8545 to another network and back—this will resync the data and restore proper functionality.
## Conclusion
You’ve achieved a lot—setting up Hardhat, configuring a local blockchain, integrating a crypto wallet, and deploying/interacting with smart contracts via a React UI.
Armed with knowledge of Hardhat, web3, and the blockchain development ecosystem, you’re ready to tackle more advanced Dapps. Next steps could include adding payment features, managing multiple contract instances, or deploying contracts to public testnets.
Start building and enjoy the process. In web3 development, the possibilities are limitless!
## FAQ
### What is Hardhat in Web3?
Hardhat is a development framework for Ethereum projects, offering tools for smart contract testing, compilation, and deployment. It’s built in JavaScript and supports all Ethereum-compatible networks.
### What is Hardhat used for?
Hardhat enables developers to write, test, and deploy Ethereum smart contracts. It features advanced debugging tools, a local testing environment, and plugin integration to accelerate Web3 application development.
### What is Hardhat software?
Hardhat is a development environment for creating, testing, and deploying Ethereum smart contracts. Its comprehensive debugging tools make it a go-to solution for blockchain developers looking to streamline their workflows.
### Is Hardhat an IDE?
No. Hardhat is not an IDE—it’s a development environment that works alongside IDEs like Visual Studio Code for authoring and managing your smart contract code.
* The information is not intended to be and does not constitute financial advice or any other recommendation of any sort offered or endorsed by Gate.