I'm new to solidity and I have to developed a ERC-20 Token. The functionality of token is almost done but in the mint function I want to cut 2% of the tokens user buy and send 1 % to liquidity pool and 1% to the owner who deployed the liquidity pool. How can I achieve this functionality ?
function mintToken(address target, uint256 mintedAmount) public onlyOwner {
balanceOf[target] += mintedAmount;
totalSupply += mintedAmount;
payable(msg.sender).transfer(mintedAmount);
emit Transfer(owner, target, mintedAmount);
}
I would advise inheriting Open Zeppelin's ERC20 contract when implementing your own token. See https://docs.openzeppelin.com/contracts/2.x/erc20 and https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol
For minting new tokens you want to use the internal_mint(target, amount)
, which mints an amount
of tokens that are owned by target
.
To do what you want, you would need to calculate the amount of tokens that should be minted to each account and then mint them to each account.
function buyTokens(uint256 amount) external {
_mint(msg.sender, (98 * amount)/100);
_mint(liquidityPoolOwnerAddress, amount/100);
_mint(liquidityPoolAddress, amount/100);
}