R
Ramoooo
Misafir
İnceledikten sonra düzeltmek gereken, ya da şu şöyle daha iyi olur dediğiniz yerleri belirtebilirsiniz
Kod:
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
contract MyToken {
string public name = "MyToken";
string public symbol = "MTK";
uint8 public decimals = 18;
uint256 public totalSupply = 1000000000 * 10**uint256(decimals);
address public owner;
uint256 public buyTaxRate = 3; // %3 alım vergisi
uint256 public sellTaxRate = 8; // %8 satım vergisi
uint256 public transferTaxRate = 2; // %2 transfer vergisi
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event Burn(address indexed from, uint256 value);
constructor() {
owner = msg.sender;
balanceOf[msg.sender] = totalSupply;
}
modifier onlyOwner() {
require(msg.sender == owner, "Only the contract owner can call this function.");
_;
}
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "Invalid new owner address.");
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
function _transfer(address _from, address _to, uint256 _value) internal {
require(_to != address(0), "Invalid recipient address.");
require(balanceOf[_from] >= _value, "Insufficient balance.");
uint256 taxAmount;
if (_from == owner) {
taxAmount = (_value * buyTaxRate) / 100;
} else if (_to == owner) {
taxAmount = (_value * sellTaxRate) / 100;
} else {
taxAmount = (_value * transferTaxRate) / 100;
}
uint256 tokensToTransfer = _value - taxAmount;
balanceOf[_from] -= _value;
balanceOf[_to] += tokensToTransfer;
emit Transfer(_from, _to, tokensToTransfer);
if (taxAmount > 0) {
balanceOf[owner] += taxAmount;
emit Transfer(_from, owner, taxAmount);
}
}
function transfer(address _to, uint256 _value) external returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) external returns (bool success) {
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) external returns (bool success) {
require(_value <= allowance[_from][msg.sender], "Transfer amount exceeds allowance.");
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
function burn(uint256 _value) external {
require(balanceOf[msg.sender] >= _value, "Insufficient balance to burn.");
balanceOf[msg.sender] -= _value;
totalSupply -= _value;
emit Burn(msg.sender, _value);
}
}