账户
0x29...c8a4
💰youngNi

💰youngNi

US$0.00
此合同的源代码已经过验证!
合同元数据
编译器
0.8.29+commit.ab55807c
语言
Solidity
合同源代码
文件 1 的 1:YN.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

contract YN {

    error TransferToZeroAddress();
    error TransferAmountExceedsBalance();
    error TransferFromZeroAddress();
    error TransferAmountExceedsAllowance();

    /// @notice Name of the token ✍️
    string public constant name = unicode"💰youngNi";

    /// @notice Symbol of the token 🏷️
    string public constant symbol = unicode"💰YN";

    /// @notice Decimal places of the token 📐
    uint8 public constant decimals = 18;

    /// @notice Initial supply of the token, fixed at 10 billion tokens 💰
    uint256 public constant INITIAL_SUPPLY = 10_000_000_000 * 10 ** uint256(decimals);

    /// @notice Total supply of the token 📈
    uint256 public totalSupply;

    /// @notice Mapping from address to token balance 📄
    mapping(address => uint256) public balanceOf;

    /// @notice Mapping from owner address to spender address to allowance amount 🗂️
    mapping(address => mapping(address => uint256)) public allowance;

    /// @notice Emitted when tokens are transferred from one address to another 🔄
    /// @param from The address from which tokens are transferred ✉️
    /// @param to The address to which tokens are transferred 📫
    /// @param value The amount of tokens transferred 🪙
    event Transfer(address indexed from, address indexed to, uint256 value);

    /// @notice Emitted when the allowance is set or increased for a spender by an owner 🔄
    /// @param owner The address of the token owner 👤
    /// @param spender The address of the spender 🤝
    /// @param value The new allowance amount 💰
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /// @dev Constructor to initialize the contract with initial supply assigned to the deployer 🏗️
    constructor() {
        totalSupply = INITIAL_SUPPLY;
        balanceOf[msg.sender] = totalSupply;
        emit Transfer(address(0), msg.sender, totalSupply);
    }

    /// @notice Transfers tokens from the sender's address to another address 🚚
    /// @param _to The address to which tokens are transferred 📩
    /// @param _value The amount of tokens to transfer 🪙
    /// @return A boolean indicating the success of the transfer ✅
    function transfer(address _to, uint256 _value) external returns (bool) {
        if (_to == address(0)) revert TransferToZeroAddress();
        uint256 senderBalance = balanceOf[msg.sender];
        if (senderBalance < _value) revert TransferAmountExceedsBalance();
        unchecked {
            balanceOf[msg.sender] = senderBalance - _value;
            balanceOf[_to] += _value;
        }
        emit Transfer(msg.sender, _to, _value);
        return true;
    }

    /// @notice Approves an address to spend a specified amount of tokens on behalf of the sender 🗂️
    /// @param _spender The address that is being approved to spend tokens 🤝
    /// @param _value The amount of tokens to be approved 💰
    /// @return A boolean indicating the success of the approval ✅
    function approve(address _spender, uint256 _value) external returns (bool) {
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }

    /// @notice Transfers tokens from one address to another using the spender's allowance 🔄
    /// @param _from The address from which tokens are transferred ✉️
    /// @param _to The address to which tokens are transferred 📫
    /// @param _value The amount of tokens to transfer 🪙
    /// @return A boolean indicating the success of the transfer ✅
    function transferFrom(address _from, address _to, uint256 _value) external returns (bool) {
        if (_from == address(0)) revert TransferFromZeroAddress();
        if (_to == address(0)) revert TransferToZeroAddress();
        uint256 fromBalance = balanceOf[_from];
        if (fromBalance < _value) revert TransferAmountExceedsBalance();
        uint256 allowed = allowance[_from][msg.sender];
        if (allowed < _value) revert TransferAmountExceedsAllowance();
        unchecked {
            balanceOf[_from] = fromBalance - _value;
            balanceOf[_to] += _value;
            allowance[_from][msg.sender] = allowed - _value;
        }
        emit Transfer(_from, _to, _value);
        return true;
    }
}
设置
{
  "compilationTarget": {
    "YN.sol": "YN"
  },
  "evmVersion": "cancun",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "enabled": true,
    "runs": 1337
  },
  "remappings": []
}
ABI
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"TransferAmountExceedsAllowance","type":"error"},{"inputs":[],"name":"TransferAmountExceedsBalance","type":"error"},{"inputs":[],"name":"TransferFromZeroAddress","type":"error"},{"inputs":[],"name":"TransferToZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"INITIAL_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]