CONTRACT

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.25;

/// @title Minimal ERC-20 implementation with fixed initial supply
/// @notice Deploys an ERC-20 compatible token and mints the full supply to the deployer
contract CONTRACT {
    error ZeroAddress();
    error InsufficientBalance();
    error InsufficientAllowance();
    error EmptyMetadata();

    string private _name;
    string private _symbol;
    uint8 private immutable _decimals;
    uint256 private _totalSupply;

    mapping(address => uint256) private _balances;
    mapping(address => mapping(address => uint256)) private _allowances;

    event Transfer(address indexed from, address indexed to, uint256 amount);
    event Approval(address indexed owner, address indexed spender, uint256 amount);

    constructor(
        string memory tokenName,
        string memory tokenSymbol,
        uint8 tokenDecimals,
        uint256 initialSupply
    ) {
        if (bytes(tokenName).length == 0 || bytes(tokenSymbol).length == 0) revert EmptyMetadata();
        _name = tokenName;
        _symbol = tokenSymbol;
        _decimals = tokenDecimals;
        _mint(msg.sender, initialSupply);
    }

    function name() external view returns (string memory) {
        return _name;
    }

    function symbol() external view returns (string memory) {
        return _symbol;
    }

    function decimals() external view returns (uint8) {
        return _decimals;
    }

    function totalSupply() external view returns (uint256) {
        return _totalSupply;
    }

    function balanceOf(address account) external view returns (uint256) {
        return _balances[account];
    }

    function allowance(address owner, address spender) external view returns (uint256) {
        return _allowances[owner][spender];
    }

    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) {
        _approve(msg.sender, spender, amount);
        return true;
    }

    function transferFrom(address from, address to, uint256 amount) external returns (bool) {
        _spendAllowance(from, msg.sender, amount);
        _transfer(from, to, amount);
        return true;
    }

    function _transfer(address from, address to, uint256 amount) internal {
        if (from == address(0) || to == address(0)) revert ZeroAddress();
        uint256 senderBalance = _balances[from];
        if (senderBalance < amount) revert InsufficientBalance();
        unchecked {
            _balances[from] = senderBalance - amount;
        }
        _balances[to] += amount;
        emit Transfer(from, to, amount);
    }

    function _approve(address owner, address spender, uint256 amount) internal {
        if (owner == address(0) || spender == address(0)) revert ZeroAddress();
        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    function _spendAllowance(address owner, address spender, uint256 amount) internal {
        uint256 currentAllowance = _allowances[owner][spender];
        if (currentAllowance < amount) revert InsufficientAllowance();
        if (currentAllowance != type(uint256).max) {
            unchecked {
                _allowances[owner][spender] = currentAllowance - amount;
            }
        }
    }

    function _mint(address to, uint256 amount) internal {
        if (to == address(0)) revert ZeroAddress();
        uint256 mintAmount = amount * (10 ** uint256(_decimals));
        _totalSupply += mintAmount;
        _balances[to] += mintAmount;
        emit Transfer(address(0), to, mintAmount);
    }
}

Tags:
ERC20, Token, Factory|addr:0x263f1a592a1a211b03d05be226ab190f5940bf2b|verified:true|block:23620314|tx:0x7c36e616c07cf12cf924d90845c9c758b5f1f686fbbb4672ae594c943274eb32|first_check:1761033672

Submitted on: 2025-10-21 10:01:14

Comments

Log in to comment.

No comments yet.