Help with taxes in smart contracts ERC

Hi everyone
I write a code , and put there taxes 5% as my client asked
My client sell his crypto to check , but didn’t receive anything
Could someone clever help me with this
Here is the code
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import "@openzeppelin/contracts/token/ERC20/ERC20.Sol";

contract K is ERC20 {

uint256 private immutable_taxPercentage;

constructor() ERC20("KS", "K") {

uint256 initialSupply = 1_000_000_000_000 * (10**18);

_mint(_msgSender(), initialSupply);

_taxPercentage = 5;

}

function transfer(address recipient, uint256 amount) public override returns (bool) {

uint256 taxAmount = (amount * taxPercentage) / 100;

uint256 transferAmount = amount - taxAmount;

_transfer_msgSender), recipient, transferAmount);

_transfer(_msgSender(), address(this), taxAmount);

return true;

  1. Please fix this stuff (it doesn't look like valid code)
  2. Please add relevant information (for example, whatever function _transfer does)
  3. There's no way for this to work, unless you're doing transferFrom under the hood
  4. You are (probably) transferring to the contract itself, which presumably is NOT your client's wallet
1 Like

Thank you bro , you are the great ))
I’m just learning
Is it difficult to fix it ?

Could you check please , I fix everything that you said

/ SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract KToken is ERC20 {
uint256 private immutable _taxPercentage;
address private immutable _taxWallet;

constructor() ERC20("K", "KF") {
    uint256 initialSupply = 1_000_000_000_000 * (10**18);
    _mint(_msgSender(), initialSupply);
    _taxPercentage = 5;
    _taxWallet = address(0xf9d2ca664e1B1A76502aca7502E2908cd178C676);
}

function transfer(address recipient, uint256 amount) public override returns (bool) {
    uint256 taxAmount = (amount * _taxPercentage) / 100;
    uint256 transferAmount = amount - taxAmount;
    _transfer(_msgSender(), recipient, transferAmount);
    _transfer(_msgSender(), _taxWallet, taxAmount);
    return true;
}

function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
    uint256 taxAmount = (amount * _taxPercentage) / 100;
    uint256 transferAmount = amount - taxAmount;

    _transfer(sender, recipient, transferAmount);
    _transfer(sender, _taxWallet, taxAmount);

    uint256 currentAllowance = allowance(sender, _msgSender());
    require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
    _approve(sender, _msgSender(), currentAllowance - amount);

    return true;
}

Why are you doing this inside function transferFrom?

I'm sorry, but it looks as if you're just "throwing stuff in" hoping that it would somehow do what you want.