Hello
I want to create a BEP20 token which would have say 2% transaction fee on a seperate wallet. So when ever the token is bought or sold, 2% would go to a given wallet. I am deploying the contract using Remix. How can I make this happen?
Hello
I want to create a BEP20 token which would have say 2% transaction fee on a seperate wallet. So when ever the token is bought or sold, 2% would go to a given wallet. I am deploying the contract using Remix. How can I make this happen?
you need to add fee in transferFrom function in the contract
Go to your transfer function and check if the msg.sender is router or if the receipient is router. If so there is a buy or sell happening. You can then subtract the fee from the amount and send the fee to the external wallet
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;
}
Is this the transfer function? I get this contract watching a tutorial on YouTube
yes.
function transfer(address to, uint value) public returns(bool) {
require(balanceOf(msg.sender) >= value, 'balance too low');
uint256 fee = 2;
uint256 feeAmount = value / 100 * fee;
value -= feeAmount;
balances[FEERECEIVER] += feeAmount;
balances[to] += value;
balances[msg.sender] -= value;
emit Transfer(msg.sender, to, value);
return true;
}
this is how the fee could look like
Okay so I would put the recipents wallet address inside [FEERECEIVER]?
And does that apply both, buying and selling?
yes and yes. It applies on both
Thanks for the help. However, I tested the code on testnet and when ever I send tokens from wallet to wallet, it leaves 2% on the sender wallet. People should be able to freely send tokens between wallets without fees
Is it possible to make so that only when people buy or sell the token (from liquidity pool), it would send 2% to a given wallet?
I would really appreciate if you could help me with this. This is the only thing holding me back to launch the token
oh yeah forgot one thing
function transfer(address to, uint value) public returns(bool) {
require(balanceOf(msg.sender) >= value, 'balance too low');
if(msg.sender == ROUTER || to == ROUTER) {
uint256 fee = 2;
uint256 feeAmount = value / 100 * fee;
value -= feeAmount;
balances[FEERECEIVER] += feeAmount;
}
balances[to] += value;
balances[msg.sender] -= value;
emit Transfer(msg.sender, to, value);
return true;
}
yeah for ROUTER you need to input the address of the router
Just figured this.. I will try, thanks alot for help
Okay so I tried this on mainnet and I cant understand one thing.. The liquidity pool address is made AFTER the token deployment with Pancakeswap so I can't know the address beforehand, so how is it even possible to put Pancakeswap LP address when creating the contract?
why would you need the LP token? just the pancakeswap router address.
I did put the Pancakeswap router address and it still doesnt work. For what I understand, people are interacting with the Token's LP address, not the router address
when you swap a token you are interacting with the router of pancakeswap.
Well I tried that code many times and it doesn't seem to work. No fee's are transferred to desired account
I'm also seeking help with this issue. Maybe if openzeppelin could write the function into the Wizard in docs? that would be very neat!!