Full Source:https://github.com/laronlineworld/NewToken/blob/main/NewToken.sol This token only deduct tax when selling on dex and tax goes to specific address and the transfer doesn't take any fee.
How to add fee when token was transfer? And fees will go to specific address.
Summary: Tokenomics will be BUY:0% SELL:5% TRANSFER OF TOKEN:5%. Is this possible?
/**
* @dev Moves `amount` of tokens from `sender` to `recipient`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[sender] = senderBalance.sub(amount);
}
bool takeFee = true;
if (_isExcludedFromFee[sender]) {
takeFee = false;
}
if(recipient==pairAddress&&takeFee){
uint256 taxFee = amount.mul(dexTaxFee).div(10000);
_balances[taxAddress] = _balances[taxAddress].add(taxFee);
emit Transfer(sender, taxAddress, taxFee);
amount = amount.sub(taxFee);
}
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}