second code for eth

 avatar
bruteCoder
plain_text
15 days ago
1.1 kB
6
Indexable
Never
metCrafter_CU
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract MyToken {
    // Public variables for token details
    string public name = "PiToken";
    string public symbol = "PTK";
    uint256 public totalSupply;

    // Mapping of addresses to balances
    mapping(address => uint256) public balances;

    // Event to log the minting of tokens
    event Mint(address indexed to, uint256 amount);
    
    // Event to log the burning of tokens
    event Burn(address indexed from, uint256 amount);

    // Mint function to create new tokens
    function mint(address _to, uint256 _value) public {
        require(_to != address(0), "Invalid address");
        totalSupply += _value;
        balances[_to] += _value;
        emit Mint(_to, _value);
    }

    // Burn function to destroy tokens
    function burn(address _from, uint256 _value) public {
        require(_from != address(0), "Invalid address");
        require(balances[_from] >= _value, "Insufficient balance");
        totalSupply -= _value;
        balances[_from] -= _value;
        emit Burn(_from, _value);
    }
}
Leave a Comment