Counter Contract - Hardhat
Build & Deploy a Counter Contract on Kite AI using Hardhat
What is Hardhat?
Hardhat is a local development environment for Ethereum-style (EVM) blockchains. It lets you: • Compile, test, and deploy contracts from your machine. • Script deployments and verifications (great for CI/CD). • Fork networks locally, run a local node, and debug with stack traces and console logging. • Use a rich plugin ecosystem (ethers.js, Etherscan-style verification, gas reporters, coverage, etc.).
In this section, we will go over Hardhat workflow:
- Set up & Scaffold project
- Write contract
- Compile
- Configure network
- Deploy via script
- Interact via console/scriptsPrerequisites:
• Node.js 18+ and npm (or pnpm/yarn)
• A funded wallet (for Kite testnet/mainnet)
• MetaMask (optional - recommended for managing keys)
• Git (recommended)1. Create a Hardhat Project:
Create and enter a new folder:
mkdir kite-counter-hardhat && cd kite-counter-hardhatInitialize a Node project:
npm init -yInstall Hardhat and tooling:
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox dotenvScaffold a Hardhat project (choose “Create a TypeScript project” when prompted):
npx hardhat
This creates a hardhat.config.ts, sample tests, and a basic project structure.
2. Add Envrironment variable:
Create a .env file in the project root
touch.env
Put your secrets and Kite endpoints in it (replace placeholders):
Wallet private key (no 0x prefix or with 0x — Hardhat supports either):
Kite AI network (testnet or mainnet) RPC:
Chain ID (number):
KITE EXPLORER URL:
.gitignore (ensure secrets aren’t committed):
3. Configure hardhat
Open hardhat.config.ts and replace with:
4. Write the Counter Contract
5. Compile
npx hardhat compile
6. Write a Deployment Script
Create scripts/deploy.ts:
7. Fund Your Deployer & Add the Network (MetaMask)
8. Deploy to Kite AI
npx hardhat run scripts/deploy.ts --network kiteTestnet
Output example: Counter deployed to: 0xABCDEF1234567890abcdef1234567890ABCDEF12
Important - Copy and save this address on your notepad.
9. Verify if deployment went through successfully
10. Troubleshooting
11. Security & Best Practices
If you wish to integrate this deployed contract to a front-end with a user interface, visit the below link and follow the steps:
Last updated
