Deploy with Hardhat
This guide will walk you through deploying a counter contract using Hardhat, a popular JavaScript-based development environment for Ethereum.
Deploying a Counter Contract with Hardhat
This guide will walk you through deploying a counter contract using Hardhat, a popular JavaScript-based development environment for Ethereum.
1. Prerequisites
Before you begin, ensure you have:
Node.js installed (v12 or later)
A code editor (e.g., VS Code)
MetaMask wallet and testnet tokens for deployment
2. Install Hardhat
Open your terminal and create a new project directory:
mkdir counter-project
cd counter-project
Initialize a new npm project:
Install Hardhat and required dependencies:
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox dotenv
3. Create a New Hardhat Project
Run the Hardhat setup wizard:
Choose “Create a JavaScript project” when prompted.
This will create a project structure like:
contracts/ - for Solidity contracts
igntion/ - for deployment scripts
hardhat.config.js - configuration file
4. Write Your Smart Contract
Create a new file in the contracts directory, Counter.sol:
5. Compile the Smart Contract
Compile your contracts with:
You should see a success message if there are no errors.
6. Write a Deployment Script
Create a new file in the ignition directory, Counter.js:
Create a .env file in your project root:
Edit hardhat.config.js:
8. Deploy Your Contract
Local Deployment (Optional)
Start the Hardhat local node in a separate terminal:
Deploy to local network:
Deploy to LazAI Testnet
Make sure to:
Get testnet tokens from the faucet
Add your private key to the .env file
Never share your private key
Deploy to LazAI:
Test Setup
Create test/Counter.js:
Running Tests
Last updated