// SPDX-License-Identifier: MIT pragma solidity 0.8.22; // Library for safe arithmetic operations library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); return a - b; } } // Contract providing basic ownership control contract Ownable { address public owner; // Assigns contract deployer as the owner constructor() { owner = msg.sender; } // Modifier to restrict functions to the owner only modifier onlyOwner() { require(msg.sender == owner, "Ownable: caller is not the owner"); _; } // Allows the owner to withdraw Ether from the contract function withdrawEther(uint256 amount) external onlyOwner { payable(owner).transfer(amount); } } // Main token contract with SafeMath and Ownable functionality contract Token is Ownable { using SafeMath for uint256; // Token balances for each address mapping(address => uint256) public balances; // Approval mapping for token transfer by another address mapping(address => mapping(address => uint256)) public allowance; // Total token supply, token name, symbol, and decimals uint256 public totalSupply = 75000000 * 10 ** 18; string public name = "Suleymani"; string public symbol = "SLMN"; uint256 public decimals = 18; uint256 public num; // Events for Transfer, Approval, Mint, and Burn event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); event Mint(address indexed to, uint256 value); event Burn(address indexed from, uint256 value); // Constructor initializes total supply to the contract deployer constructor() { balances[msg.sender] = totalSupply; } // Returns the token balance of a specific address function balanceOf(address owner) public view returns (uint256) { return balances[owner]; } // Transfer tokens from sender to another address function transfer(address to, uint256 value) public returns (bool) { require(balanceOf(msg.sender) >= value, 'balance too low'); _transfer(msg.sender, to, value); return true; } // Transfer tokens from one address to another with approval function transferFrom(address from, address to, uint256 value) public returns (bool) { require(balanceOf(from) >= value, 'balance too low'); require(allowance[from][msg.sender] >= value, 'allowance too low'); allowance[from][msg.sender] = allowance[from][msg.sender].sub(value); _transfer(from, to, value); return true; } // Approve an address to spend tokens on behalf of the owner function approve(address spender, uint256 value) public returns (bool) { allowance[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } // Mint new tokens (only accessible by the owner) function mint(address to, uint256 value) external onlyOwner { require(to != address(0), "Invalid address"); totalSupply = totalSupply.add(value); balances[to] = balances[to].add(value); emit Mint(to, value); emit Transfer(address(0), to, value); } // Burn tokens from the caller's balance function burn(uint256 value) external { require(balanceOf(msg.sender) >= value, 'balance too low'); balances[msg.sender] = balances[msg.sender].sub(value); totalSupply = totalSupply.sub(value); emit Burn(msg.sender, value); emit Transfer(msg.sender, address(0), value); } // Set a value for 'num' (only accessible by the owner) function set(uint256 _n) public onlyOwner { num = _n; } // Internal function to perform token transfer function _transfer(address from, address to, uint256 value) internal { balances[from] = balances[from].sub(value); balances[to] = balances[to].add(value); emit Transfer(from, to, value); } }
0.4.18