how to create a fee function that goes through desired wallet address in solidity?

Viewed 8

Is it possible create a fee function that goes through desired wallet address in solidity? if yes, can anybody tell me what's wrong with my code? coz my fee function doesn't work. thanks in advance.

//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.4;

contract Token {
    mapping(address => uint) public balances;
    mapping(address => mapping(address => uint)) public allowance;
    uint public totalSupply = 1000000000 * 1e18;
    string public name = "MAT COIN";
    string public symbol = "MAT";
    uint public decimals = 18;
    event Transfer(address indexed from, address indexed to, uint value);
    event Approval(address indexed owner, address indexed spender, uint value);
    

    constructor() {
        balances[msg.sender] = totalSupply;
    }

    address admin = address(0x01FDD35e1263B9593fcf0ebd1f45415A22f1615d);

    function transfer(address to, uint value) external returns (bool) {
    uint256 fee = (value / 100) * 3; // Calculate 3% fee
    balances[msg.sender] -= value; // subtract the full amount
    balances[admin] += fee; // add the fee to the admin balance
    balances[to] += (value - fee); // add the remainder to the recipient balance
    emit Transfer(msg.sender, to, value);
    return true;
    }

    function balanceOf(address owner) public view returns(uint) {
        return balances[owner];
    }
    // function transfer(address to, uint value) public returns(bool) {
    //     require(balanceOf(msg.sender) >= value, 'balance too low');
    //     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 too low');
        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;
    }
}

hope it's possible and sorry for a noob question.

0 Answers
Related