This project is a custom-built, security-focused implementation of an ERC20 token, created from scratch without using any external libraries like OpenZeppelin. It's fully tested and achieves 100% test coverage using Foundry's forge coverage.
- ✅ Built fully from scratch (no external dependencies)
- 🔐 Secure error handling with custom errors
- 🧪 100% test coverage with Foundry
- 👨💻 Owner-only
mintfunctionality - 🔥 Public
burnfunctionality - 📥
approve,transferFrom,increaseAllowance,decreaseAllowancesupport - 🚫 Custom reverts for cleaner gas-efficient error messages
- 🧱
MAX_SUPPLYconstraint enforced
| Function | Description |
|---|---|
constructor |
Initializes token with name, symbol, decimals, and initial supply |
mint() |
Owner-only function to mint tokens without exceeding MAX_SUPPLY |
burn() |
Burns caller's tokens |
transfer() |
Transfers tokens to another address |
approve() |
Approves a spender to spend on caller's behalf |
transferFrom() |
Allows spending tokens via allowance |
increaseAllowance() |
Safely increases allowance for a spender |
decreaseAllowance() |
Safely decreases allowance for a spender |
Custom errors are used instead of revert strings to save gas and improve readability:
MyToken__NotOwner()MyToken__MaxSupplyExceeds()MyToken__NotEnoughTokens()MyToken__InvalidAddress()MyToken__AllowanceExceeds()MyToken__NotEnoughAllowance()
- Solidity:
^0.8.24 - Framework: Foundry
- Test Coverage: 100% via
forge coverage
git clone https://github.com/Eunum56/foundry-ERC20
cd foundry-ERC20forge install
forge build
forge testFeel free to fork this repository and submit pull requests. If you have suggestions or encounter any bugs, please open an issue in the GitHub repository.
Built with ❤️, tested with 🧪, and deployed with 💪