ETH Price: $2,853.44 (-2.99%)

Contract Diff Checker

Contract Name:
ElonCoin

Contract Source Code:

File 1 of 1 : ElonCoin

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract ElonCoin {
    // Public token variables
    string public name = "ElonCoin";
    string public symbol = "ELCN";
    uint8 public decimals = 18; // ERC20 standard is 18 decimals
    uint256 public totalSupply;

    // Mapping to store the balances and allowances
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    // Events required by the ERC20 standard
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    // Constructor to set the initial supply and assign it to the deployer of the contract
    constructor() {
        totalSupply = 21000000 * (10 ** uint256(decimals)); // Adjust total supply to 21,000,000 with decimals
        balanceOf[msg.sender] = totalSupply; // Assign all tokens to the contract's deployer
        emit Transfer(address(0), msg.sender, totalSupply); // Emit a Transfer event for initial supply
    }

    // Function to transfer tokens to a specific address
    function transfer(address _to, uint256 _value) public returns (bool success) {
        require(_to != address(0), "Invalid address");
        require(_value <= balanceOf[msg.sender], "Insufficient balance");

        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;

        emit Transfer(msg.sender, _to, _value);
        return true;
    }

    // Function to approve someone to spend tokens on behalf of the sender
    function approve(address _spender, uint256 _value) public returns (bool success) {
        require(_spender != address(0), "Invalid address");

        allowance[msg.sender][_spender] = _value;

        emit Approval(msg.sender, _spender, _value);
        return true;
    }

    // Function to transfer tokens from one address to another using allowance
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        require(_to != address(0), "Invalid address");
        require(_value <= balanceOf[_from], "Insufficient balance");
        require(_value <= allowance[_from][msg.sender], "Allowance exceeded");

        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;
        allowance[_from][msg.sender] -= _value;

        emit Transfer(_from, _to, _value);
        return true;
    }

    // Function to increase the allowance
    function increaseAllowance(address _spender, uint256 _addedValue) public returns (bool success) {
        require(_spender != address(0), "Invalid address");

        allowance[msg.sender][_spender] += _addedValue;

        emit Approval(msg.sender, _spender, allowance[msg.sender][_spender]); // Accessing specific allowance
        return true;
    }

    // Function to decrease the allowance
    function decreaseAllowance(address _spender, uint256 _subtractedValue) public returns (bool success) {
        require(_spender != address(0), "Invalid address");
        uint256 currentAllowance = allowance[msg.sender][_spender];
        require(_subtractedValue <= currentAllowance, "Decreased allowance below zero");

        allowance[msg.sender][_spender] -= _subtractedValue;

        emit Approval(msg.sender, _spender, allowance[msg.sender][_spender]); // Accessing specific allowance
        return true;
    }
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):