Skip to content

joaquimafn/ERC20-with-openzeppelin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MyToken - Secure ERC-20 Contract with Foundry

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.

Token Characteristics

  • 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

Security Features

  • Reentrancy Protection: Implementation of the nonReentrant modifier 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

Prerequisites

Installation

# Clone the repository
git clone <REPOSITORY_URL>
cd <DIRECTORY_NAME>

# Install dependencies
forge install

Compilation

forge build

Tests

forge test

To see test details:

forge test -vv

Deployment

Configuration

Create a .env file in the project root with your private key:

PRIVATE_KEY=your_private_key_here

Deploy to a test network

# 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 --verify

Project Structure

  • src/MyToken.sol: ERC-20 contract implementation
  • script/MyToken.s.sol: Contract deployment script
  • test/MyToken.t.sol: Contract tests

Contract Features

Basic Functions

Mint

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) nonReentrant

Burn

Any user can burn their own tokens, as long as they are not blacklisted.

function burn(uint256 amount) public whenNotPaused notBlacklisted(msg.sender) nonReentrant

Standard ERC-20 Functions

The contract implements all standard ERC-20 functions, with additional protections:

  • transfer: Transfer tokens to another address
  • approve: Approve another address to spend tokens on your behalf
  • transferFrom: Transfer tokens from one address to another (requires approval)
  • balanceOf: Check the balance of an address
  • allowance: Check how much one address can spend on behalf of another

Security Functions

Pausability

function pause() public onlyOwner
function unpause() public onlyOwner

Blacklist Management

function blacklistAddress(address account) public onlyOwner
function unblacklistAddress(address account) public onlyOwner

Timelock for Critical Operations

function initiateTimelock(bytes32 operationId) public onlyOwner

Transaction Limit Configuration

function initiateMaxTransactionAmountUpdate(uint256 amount) public onlyOwner
function getMaxTransactionAmountOperationId(uint256 amount) public view returns (bytes32)
function setMaxTransactionAmount(uint256 amount, uint256 timestamp) public onlyOwner

License

MIT

About

create ERC-20 token

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors