I'm making a system that adds a fee to every transaction of my ERC20 token.
I have two files, wiseth_v1.sol and ERC20Mod.sol written in Solidity.
ERC20.sol is a modification of the ERC20.sol Openzeppelin's contract.
wiseth_v1.sol first lines:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "./ERC20Mod.sol";
contract Wiseth is ERC20, Ownable {
using SafeMath for uint256;
uint deployDate;
uint daHour;
bool isPassed;
bytes32 num_type;
uint public percentage;
As you can see, the parent contract is ERC20Mod.sol and its child is wiseth_v1.sol (the true token's script).
The owner of the contract sets the fee's percentage with this function (wiseth_v1.sol):
function setFirstPercentageFee(uint256 fee) external onlyOwner {
percentage = fee;
}
And this is the transferFrom
function of the transaction on ERC20Mod.sol:
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
uint256 fee = (amount.mul(percentage)).div(10000);
uint256 total = amount.sub(fee);
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, total);
return true;
}
When calculating the fee uint256 fee = (amount.mul(percentage)).div(10000);
i need to take the "percentage" uint256 from wiseth_v1.sol, how do i do that? Any help is appreciated. (I don't want to put the wiseth_v1.sol code in ERC20Mod.sol, i want to keep them separate. Thanks.
I searched on Google but only found how to take parent variables in its child. I use remix.ethereum.org