Token Tokenomics will be like this: Buy: 0% Sell/Transfer: 5% and 5% goes to charity address. This is the token contract:https://bscscan.com/address/0xfe03a2004648886987cf4b8fd433b1b132740121#code This token already applied the 0 buy fee and 5% fee on sell, but the missing puzzle is the fee for transferring token from one address to another. Any help or advice willbe a big help.
1 Answer
This should work
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(sender == pairAddress || !takeFee){ //checks if the sender is the uniswap pair or if its excluded from fees, doesnt take any fees if one of these conditions are true.
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
else { // takes the fees normally otherwise
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);
}
}
-
hi @Foxxxey, does changing the
transfer()
function break the ERC20 convention? Will you still be able to add your token to Dex after that?– foufrixCommented Oct 6, 2022 at 16:32 -
It doesn't break the spec in itself, but it makes it so when you're transferring tokens, the amount received is less than the amount sent, which can certainly break some contracts. For example, uniswap v2 supports that but uniswap v3 doesnt (well, the router doesnt).– FoxxxeyCommented Oct 6, 2022 at 19:23
-
ok thanks for the specification, so depends on dex, and need to check manually where it will break.– foufrixCommented Oct 7, 2022 at 7:44