How to create a burnable and pauseable ERC20 in OpenZeppelin 3.1.0 using Solidity 7.1

I am new in block-chain and want to create my erc20 token using Oppenzeppelin. When, I inherit these files

  1. import “@openzeppelin/contracts/token/ERC20/ERC20.sol”;
  2. import “@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol”;
  3. import “@openzeppelin/contracts/token/ERC20/ERC20Pausable.sol”;

Then, I get this error.

Derived contract must override function “_beforeTokenTransfer”. Two or more base classes define function with same name and parameter types.

What should I do to solve this issue.

1 Like

Hi @hussammustafa,

Welcome to the community :wave: and blockchain development.

To resolve the issue you can add the following to your contract:

    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override(ERC20, ERC20Pausable) {
        super._beforeTokenTransfer(from, to, amount);
    }

You can see an example of this in ERC20PresetMinterPauser

To learn more about hooks, please see the documentation: https://docs.openzeppelin.com/contracts/3.x/extending-contracts#using-hooks

2 Likes

Thank You, You responded to my Query. I need to know one more thing that, if i add ERC20Capped in contract. Then why it say’s:

“Contract “CustomToken” should be marked as abstract.”.

1 Like

Hi @hussammustafa,

I assume as well as inheriting from ERC20Capped you also need to add an override for _beforeTokenTransfer

    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override(ERC20, ERC20Pausable, ERC20Capped) {
        super._beforeTokenTransfer(from, to, amount);
    }