我想添加一个交易税功能,收取发送者金额的 2.5% 以发送到所有者钱包地址。我该怎么做这个功能。
谢谢。
pragma solidity ^0.8.2;
contract Token {
mapping(address => uint) public balances;
mapping(address => mapping(address => uint)) public allowance
uint public totalSupply = 1,000,000,000,000 * 10 ** 18; // Total supply and the smallest denomination
string public name = "My Token"; // Name of Token
string public = "TKN"; //Token Symbol
uint public decimal = 18; // Denoting smallest denomination and the number of decimals.(8 or 18)
event Transfer(address indexed from , address indexed to ,uint value);
constructor(){
balances[msg.sender] = totalSupply;
}
//All the function names are required by the Bep20 standard
function balanceOf(address owner) public view returns(uint){
return balanceOf[owner];
}
function tranfser(address to , uint value) public returns(bool)
require(balanceOf(msg.sender) >= value, 'balance is insufficient for transfer');
balances[to] += value;
balances[msg.sender] -= value;
emit Transfer(msg.sender, to , value);
return true;
)
function transferFrom(address from, address to ,uint value) public returns(bool){
require (balanceOf(from) >= value, "balance is insufficient for transfer");
require(allowance(from)[msg.sender] >= 'value',"allowance too low ") ;
balances[to] += value;
balances[from] -= value;
emit Transfer(from, to, value);
return True;
}
function approve(address spender, uint value) public returns(bool){
allowance[msg.sender][spender] = value;
emit Approval(msg.sender,spender,value);
return true;
}
}