I am trying to implement an ERC20
token that inherits ERC20.sol
, ERC20Detailed.sol
, ERC20Burnable.sol
, ERC20Mintable.sol
, and ERC20Pausable.sol
.
contract DemoContract is ERC20,ERC20Detailed,ERC20Burnable,ERC20Mintable, ERC20Pausable {
constructor(uint256 initialSupply) ERC20Detailed("Test Token", "TEST", 18) public {
_mint(msg.sender, initialSupply);
}
}
The function _beforeTokenTransfer
is defined in ERC20.sol
as follows:
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
and in ERC20Pausable.sol
as follows:
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
super._beforeTokenTransfer(from, to, amount);
require(!paused(), "ERC20Pausable: token transfer while paused");
}
When I try to compile my contracts using truffle framework, I get the following error:
TypeError: Derived contract must override function "_beforeTokenTransfer". Two or more base classes define function with same name and parameter types.
contract DemoContract is ERC20,ERC20Detailed,ERC20Burnable,ERC20Mintable, ERC20Pausable {
^ (Relevant source part starts here and spans across multiple lines).
I cannot seem to understand why this error occurs although override is used in the ERC20Pausable.sol
.
Here are the new contracts after removing ERC20 from the DemoContract:
contract ERC20 is Context, IERC20
contract ERC20Detailed is ERC20
abstract contract ERC20Burnable is Context, ERC20
abstract contract ERC20Mintable is ERC20, MinterRole
abstract contract ERC20Pausable is ERC20, Pausable
contract DemoContract is ERC20Detailed,ERC20Burnable,ERC20Mintable, ERC20Pausable
However, the error still remains.