This project implements a custom ERC20-like token called MyToken with a 1% transfer fee, deployed on Ethereum. It includes smart contracts written in Solidity, a frontend DApp for interacting with the token, and uses Hardhat for development, testing, and deployment.
This blockchain lab project demonstrates:
- MyToken Smart Contract: A custom token contract with transfer functionality and a 1% fee on transfers.
- Frontend DApp: A web application using ethers.js to connect to MetaMask, display wallet balance, and perform token transfers.
- Hardhat Development Environment: For compiling, testing, and deploying contracts.
- Ignition Deployment: For automated contract deployment.
- ERC20-like token with name, symbol, and balance tracking
- Transfer function with a 1% fee (burned on transfer)
- MetaMask integration for wallet connection
- Sepolia testnet support
- Simple, responsive UI for token management
- Node.js (v18 or higher)
- MetaMask browser extension
- Sepolia ETH for deployment and transactions (can be obtained from faucets)
- Clone the repository:
git clone https://github.com/redpanda02/Lab14-Blockchain.git
cd Lab14-Blockchain- Install dependencies:
npm installnpx hardhat compileRun all tests:
npx hardhat testRun Solidity tests only:
npx hardhat test solidity-
Create an Ignition module for MyToken deployment (see
ignition/modules/Counter.tsas example). -
Deploy to local network:
npx hardhat ignition deploy ignition/modules/MyToken.ts- Deploy to Sepolia testnet:
- Set your private key:
npx hardhat keystore set SEPOLIA_PRIVATE_KEY - Deploy:
npx hardhat ignition deploy --network sepolia ignition/modules/MyToken.ts
- Set your private key:
-
Update the contract address in
frontend/index.html(line 69) with your deployed contract address. -
Open
frontend/index.htmlin a web browser. -
Connect your MetaMask wallet and switch to Sepolia network.
-
View your token balance and transfer tokens to other addresses.
- Token Name: MyToken (MTK)
- Contract Address: 0x3c78dc361a24b4a06253db4996754b9049a06b51
- Live DApp URL: [Host frontend on GitHub Pages/Netlify and update here]
-
Set up secrets:
npx hardhat vars set SEPOLIA_RPC_URL # Paste your Alchemy/Infura URL npx hardhat vars set SEPOLIA_PRIVATE_KEY # Paste your MetaMask private key
-
Deploy to Sepolia:
npx hardhat run scripts/deploy.ts --network sepolia
Copy the deployed address and update
frontend/index.htmlline 69 and this README. -
Verify contract:
npx hardhat verify --network sepolia 0x3c78dc361a24b4a06253db4996754b9049a06b51 "MyToken" "MTK" 1000000
-
Host frontend: Enable GitHub Pages for the
frontendfolder in repository settings, or upload to Netlify, and update the URL here.
contracts/: Solidity smart contractsMyToken.sol: Main token contractMyTokenBase.sol: Base contract with core functionalityIMyToken.sol: Token interface
frontend/: Web frontendindex.html: Complete DApp interface
ignition/modules/: Deployment scriptstest/: Test filesscripts/: Utility scripts
- MyToken: Inherits from MyTokenBase, sets name, symbol, and initial supply
- Transfer Fee: 1% of transfer amount is deducted from sender's balance
- Initial Supply: Set during deployment
- Decimals: Not implemented (assumed 0 for simplicity)
This project uses Hardhat 3 Beta with viem for Ethereum interactions and Node.js native test runner.
For more information on Hardhat, visit hardhat.org.