Description:
ERC20 token contract with Factory capabilities. Standard implementation for fungible tokens on Ethereum.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
/// @title SimpleERC20 - fixed supply ERC20 token
/// @notice All tokens are minted to deployer on contract creation. Decimals = 18.
contract SimpleERC20 {
string public name;
string public symbol;
uint8 public immutable decimals = 18;
uint256 public totalSupply;
mapping(address => uint256) private _balanceOf;
mapping(address => mapping(address => uint256)) private _allowance;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
constructor(
string memory _name,
string memory _symbol,
uint256 _initialSupply // supply in whole tokens (without decimals)
) {
name = _name;
symbol = _symbol;
uint256 supplyWithDecimals = _initialSupply * (10 ** uint256(decimals));
totalSupply = supplyWithDecimals;
_balanceOf[msg.sender] = supplyWithDecimals;
emit Transfer(address(0), msg.sender, supplyWithDecimals);
}
/* ===== ERC20 read functions ===== */
function balanceOf(address account) external view returns (uint256) {
return _balanceOf[account];
}
function allowance(address owner, address spender) external view returns (uint256) {
return _allowance[owner][spender];
}
/* ===== ERC20 core functions ===== */
function transfer(address to, uint256 amount) external returns (bool) {
_transfer(msg.sender, to, amount);
return true;
}
function approve(address spender, uint256 amount) external returns (bool) {
_allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) external returns (bool) {
uint256 currentAllowance = _allowance[from][msg.sender];
require(currentAllowance >= amount, "ERC20: exceeds allowance");
_allowance[from][msg.sender] = currentAllowance - amount;
emit Approval(from, msg.sender, _allowance[from][msg.sender]);
_transfer(from, to, amount);
return true;
}
/* ===== internal helper ===== */
function _transfer(address from, address to, uint256 amount) internal {
require(to != address(0), "ERC20: transfer to zero");
uint256 fromBal = _balanceOf[from];
require(fromBal >= amount, "ERC20: exceeds balance");
_balanceOf[from] = fromBal - amount;
_balanceOf[to] += amount;
emit Transfer(from, to, amount);
}
}
Submitted on: 2025-10-24 18:22:22
Comments
Log in to comment.
No comments yet.