startToken.sol

 avatar
bruteCoder
plain_text
a year ago
1.4 kB
7
Indexable
metCrafter_CU
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;

contract StarToken {

    // Public variables for token details
    string public tokenName;
    string public tokenAbbrv;
    uint public totalSupply;

    // Mapping to store balances
    mapping(address => uint) public balances;

    // Events to emit on minting and burning tokens
    event Mint(address indexed to, uint256 amount);
    event Burn(address indexed from, uint256 amount);

    // Constructor to initialize the token details
    constructor() {
        tokenName = "StarCoin";
        tokenAbbrv = "STAR";
        totalSupply = 0;
    }

    // Function to mint new tokens
    function mint(address _to, uint _amount) public {
        require(_to != address(0), "Mint to the zero address is not allowed");
        totalSupply += _amount;
        balances[_to] += _amount;
        emit Mint(_to, _amount);
    }

    // Function to burn existing tokens
    function burn(address _from, uint _amount) public {
        require(_from != address(0), "Burn from the zero address is not allowed");
        require(balances[_from] >= _amount, "Insufficient balance to burn");
        balances[_from] -= _amount;
        totalSupply -= _amount;
        emit Burn(_from, _amount);
    }

    // Function to get the balance of an account
    function balanceOf(address _account) public view returns (uint) {
        return balances[_account];
    }
}
Editor is loading...
Leave a Comment