Skip to content

jameslego-ctrl/foundry-ERC20

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

INTRODUCTION

Project Overview – Custom ERC20 Token Implementations This project contains two Solidity smart contracts showcasing different approaches to implementing ERC-20-like tokens on Ethereum and EVM-compatible blockchains.

🎯 Purpose : The goal of this repository is to demonstrate:

1.	Manual ERC-20-like Implementation — building token logic from scratch without importing external libraries.

2.	Standard ERC-20 Implementation using OpenZeppelin’s battle-tested library for security and compatibility.

This dual approach gives developers a hands-on understanding of:

•	How the ERC-20 standard works internally.

•	The benefits of using audited libraries like OpenZeppelin.

•	Security considerations when working with token balances and transfer logic.

ManualToken

A simple ERC20-like token smart contract written in Solidity without using the official ERC20 standard interface. This project demonstrates how token balances, transfers, and metadata (name, decimals, total supply) can be implemented manually.


TABLE OF CONTENT

  1. CONTRACT OVERVIEW
  2. FILE STRUCTURE
  3. SECURITY NOTES

CONTRACT OVERVIEW

ManualToken.sol is a lightweight token implementation for educational purposes. It stores balances in a mapping and provides functions for reading token metadata and transferring tokens.

OurToken.sol is a simple but secure implementation of the ERC-20 token standard, built on top of OpenZeppelin’s audited contract library. The contract defines a fungible token named “OurToken” with symbol “OT” and mints the specified initial supply to the deploying address.

ManualToken.sol Features

Token Metadata

•	`name()` → Returns `"Manual Token"`.
•	`totalSupply()` → Returns 100 tokens (`100 ether` = 100 × 10¹⁸ units).
•	`decimals()` → Returns 18 decimals.

Balance Tracking

•	`balanceOf(address)` → Returns the token balance of any address.

Token Transfers

•	`transfer(address _to, uint256 _amount)` → Moves tokens from the sender to the recipient.
•	Ensures the sum of both balances remains consistent after transfer (basic integrity check).

Limitations:

•	No minting/burning.
•	No approvals/allowances.
•	No initial distribution logic — balances must be manually set.
•	Potential underflow if sender does not have enough balance (needs `require` check).

OurToken.sol Features

A fully ERC-20 compliant token built on OpenZeppelin’s ERC20 contract.

Key Details:

Meta

•	Name: `"OurToken"`
•	Symbol: `"OT"`
•	Decimals: `18` (default for ERC-20)

Constructor:

•	Accepts an `initialSupply` parameter at deployment.
•	Automatically mints the full amount to the deployer’s address.

Benefits:

•	Inherits all ERC-20 functions (`transfer`, `approve`, `transferFrom`, `allowance`, `balanceOf`, `totalSupply`, etc.).
•	Uses Solidity 0.8.x’s automatic overflow/underflow protection.
•	Security and interoperability ensured by OpenZeppelin’s audit track record.

🔍 Purpose: Production-ready ERC-20 template for real-world deployments.


FILE STRUCTURE

.
├── src
│   └── ManualToken.sol
|   |__ OurToken.sol
|
├── lib
|
|__ script
|   |__ DeployOurToken.s.sol
|
|__test
|   |__OurToken.t.sol
|
└── foundry.toml 
|
|__ Makefile


SECURITY NOTES

• ManualToken.sol should NOT be used in production without proper checks, events, and ERC-20 compliance.

• OurToken.sol is built on a secure base, but always audit before deployment.

• Initial supplies and role management should be carefully planned to avoid centralization pitfalls.


Foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust. Foundry consists of:

  • Forge: Ethereum testing framework (like Truffle, Hardhat and DappTools).
  • Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
  • Anvil: Local Ethereum node, akin to Ganache, Hardhat Network.
  • Chisel: Fast, utilitarian, and verbose solidity REPL.

Documentation

https://book.getfoundry.sh/

Usage

Build

$ forge build

Test

$ forge test

Format

$ forge fmt

Gas Snapshots

$ forge snapshot

Anvil

$ anvil

Deploy

$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>

Cast

$ cast <subcommand>

Help

$ forge --help
$ anvil --help
$ cast --help

About

This is a simple project demonstrating ERC20

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published