Untitled
// SPDX-License-Identifier: SEE LICENSE IN LICENSE pragma solidity ^0.8.24; contract Token { string public name = "Meadow Token"; string public symbol = "MDW"; uint256 public totalSupply = 1000000; // 10e6 address public owner; mapping (address => uint256) balances; mapping (address => mapping (address => uint256)) allowances; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _from, address indexed _to, uint256 _value); constructor() { balances[msg.sender] = totalSupply; owner = msg.sender; } // Write functions function transfer(address to, uint256 amount) external { require(balances[msg.sender] >= amount, "Insufficient balance"); balances[msg.sender] -= amount; balances[to] += amount; emit Transfer(msg.sender, to, amount); } function transferFrom(address from, address to, uint256 amount) external { require(balances[from] >= amount, "Insufficient balance"); require(allowances[from][msg.sender] >= amount, "Insufficient allowance"); balances[from] -= amount; balances[to] += amount; allowances[from][msg.sender] -= amount; emit Transfer(from, to, amount); } function approve(address spender, uint256 amount) external { require(balances[msg.sender] >= amount, "Insufficient balance"); allowances[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); } function increaseAllowance(address spender, uint256 addedValue) external { require(balances[msg.sender] >= addedValue, "Insufficient balance"); allowances[msg.sender][spender] += addedValue; emit Approval(msg.sender, spender, allowances[msg.sender][spender]); } function decreaseAllowance(address spender, uint256 subtractedValue) external { require(balances[msg.sender] >= subtractedValue, "Insufficient balance"); require(allowances[msg.sender][spender] >= subtractedValue, "Insufficient allowance"); allowances[msg.sender][spender] -= subtractedValue; emit Approval(msg.sender, spender, allowances[msg.sender][spender]); } // Read functions function balanceOf(address account) external view returns (uint256) { return balances[account]; } function allowance(address from, address to) external view returns (uint256) { return allowances[from][to]; } }
Leave a Comment