Final Project: Build a Simple Token Contract
Combine everything from this course into a simple, ERC-20-style fungible token contract, the same basic pattern underlying most tokens on Ethereum.
Requirements
- Declare state variables for
name,symbol,totalSupply, and amapping(address => uint256)for balances. - In the constructor, mint the entire
totalSupplytomsg.sender(the deployer). - Implement
function transfer(address to, uint256 amount) public returns (bool), usingrequireto check the sender has enough balance, updating both balances, and emitting aTransferevent. - Implement
function balanceOf(address account) public view returns (uint256). - Add an
onlyOwner-style modifier and amint(address to, uint256 amount)function restricted to the contract's owner, that increasestotalSupplyand the recipient's balance. - Use a custom error (not a plain string) for the insufficient-balance case in
transfer.
Stretch goals
- Add
approve/transferFromto support spending on someone else's behalf (the rest of the real ERC-20 standard). - Add a
burn(uint256 amount)function that destroys tokens from the caller's own balance. - Write a few test cases (using Hardhat or Foundry) proving transfer fails correctly when the sender has insufficient balance.
Submit a link to your finished contract below, an instructor will review it before you can mark this lesson complete. Good luck!