This project implements a custom and secure ERC-20 token using Foundry, a development tool for Ethereum. The contract includes mint and burn functionalities, with a limited maximum supply, as well as various security protections to ensure the robustness of the contract.
- Name: MyToken
- Symbol: MTK
- Decimals: 18
- Initial Supply: 100,000 tokens
- Maximum Supply: 1,000,000 tokens
- Basic Functionalities: Mint (owner only), Burn, Transfer, Approve, TransferFrom
- Reentrancy Protection: Implementation of the
nonReentrantmodifier to prevent reentrancy attacks - Pausability: Ability to pause all transfers in case of emergency
- Blacklist: Possibility to block malicious addresses
- Transaction Limit: Maximum limit per transaction to prevent market manipulation
- Timelock: Waiting period for critical operations
- Additional Validations: Zero address checks, positive values, etc.
- Detailed Events: Emission of events for all critical operations for better auditability
# Clone the repository
git clone <REPOSITORY_URL>
cd <DIRECTORY_NAME>
# Install dependencies
forge installforge buildforge testTo see test details:
forge test -vvCreate a .env file in the project root with your private key:
PRIVATE_KEY=your_private_key_here
# Load environment variables
source .env
# Deploy to Sepolia network
forge script script/MyToken.s.sol --rpc-url https://sepolia.infura.io/v3/YOUR_INFURA_ID --broadcast --verifysrc/MyToken.sol: ERC-20 contract implementationscript/MyToken.s.sol: Contract deployment scripttest/MyToken.t.sol: Contract tests
Only the contract owner can create new tokens, up to the maximum limit of 1,000,000 tokens.
function mint(address to, uint256 amount) public onlyOwner whenNotPaused notBlacklisted(to) nonReentrantAny user can burn their own tokens, as long as they are not blacklisted.
function burn(uint256 amount) public whenNotPaused notBlacklisted(msg.sender) nonReentrantThe contract implements all standard ERC-20 functions, with additional protections:
transfer: Transfer tokens to another addressapprove: Approve another address to spend tokens on your behalftransferFrom: Transfer tokens from one address to another (requires approval)balanceOf: Check the balance of an addressallowance: Check how much one address can spend on behalf of another
function pause() public onlyOwner
function unpause() public onlyOwnerfunction blacklistAddress(address account) public onlyOwner
function unblacklistAddress(address account) public onlyOwnerfunction initiateTimelock(bytes32 operationId) public onlyOwnerfunction initiateMaxTransactionAmountUpdate(uint256 amount) public onlyOwnerfunction getMaxTransactionAmountOperationId(uint256 amount) public view returns (bytes32)function setMaxTransactionAmount(uint256 amount, uint256 timestamp) public onlyOwnerMIT