This project demonstrates a simple ERC20 token implementation with a React frontend.
The project includes a simple ERC20 token contract created with OpenZeppelin:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract Erc20Token is ERC20, Ownable {
constructor(
string memory name,
string memory symbol,
uint256 initialSupply,
address initialOwner
) ERC20(name, symbol) Ownable(initialOwner) {
_mint(initialOwner, initialSupply * 10 ** decimals());
}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
function burn(uint256 amount) public {
_burn(msg.sender, amount);
}
}To deploy the contract:
- Install Hardhat:
npm install --save-dev hardhat - Create a new Hardhat project:
npx hardhat init - Install OpenZeppelin:
npm install @openzeppelin/contracts - Copy the
Erc20Token.solcontract into yourcontracts/directory - Create a deployment script:
// scripts/deploy.js
async function main() {
const [deployer] = await ethers.getSigners();
console.log("Deploying contracts with the account:", deployer.address);
const Erc20Token = await ethers.getContractFactory("Erc20Token");
const token = await Erc20Token.deploy(
"My Token", // name
"MTK", // symbol
"1000000", // initialSupply
deployer.address, // initialOwner
);
await token.deployed();
console.log("Token deployed to:", token.address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});- Run the deployment:
npx hardhat run scripts/deploy.js --network <your-network>
The frontend uses:
- Next.js for the React framework
- Wagmi and Viem for Ethereum interactions
- Shadcn UI components for the interface
- Deploy new ERC20 tokens (in actual deployment this would use Hardhat/Foundry)
- Interact with existing tokens (check balance, get info)
- Transfer tokens to other addresses
- Install dependencies:
npm install - Run the development server:
npm run dev - Visit http://localhost:3000/token to use the app
- Node.js
- Metamask or other Web3 wallet
- Access to Ethereum testnet (Sepolia recommended)