Hi,
I’m implementing an ERC20 token getting inspired by ERC20PresetMinterPauser.sol.
I’m not inheriting the preset cause I would like to inherit Ownable.sol add extra functions (like permit()) and have everything in one smart contract.
My question is do I need to include the following function?
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override(ERC20, ERC20Pausable) {
super._beforeTokenTransfer(from, to, amount);
}
I’m learning about hooks and it’s not completely clear to me the utility of this particular function.
So, If my understanding is correct, it should override both ERC20.sol and ERC20Pausable _beforeTokenTransfer() hooks with this one that should call the one in ERC20Pausable:
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
super._beforeTokenTransfer(from, to, amount);
require(!paused(), "ERC20Pausable: token transfer while paused");
}
That require that the smart contract is not paused, otherwise it will revert _mint(), _burn() and _transfer(), right?
Also, If I should include this function, should I add the attribute “virtual” to it, allowing other contracts to override it? isn’t it unsafe?
Cause here specify to always add the virtual attribute to the hook when overriding:
https://docs.openzeppelin.com/contracts/3.x/extending-contracts#rules_of_hooks
Thanks!
Environment
Truffle v5.1.33 (core: 5.1.33)
Solidity - 0.6.11 (solc-js)
Node v12.18.2
Web3.js v1.2.1
Details
Code to reproduce