How can I make an ERC20 both Burnable and Detailed?

I’m trying to build a token with its ticker, name, and decimals specified, while also being burnable. I’m importing ERC20Detailed and ERC20Burnable. But my Remix compiler throws:

browser/GGCoin.sol:4:1: DeclarationError: Identifier already declared. import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/ERC20Burnable.sol"; ^--------------------------------------------------------------------------------------------------------------------------^ https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC20/IERC20.sol:7:1: The previous declaration is here: interface IERC20 { ^ (Relevant source part starts here and spans across multiple lines).

I suspect this is because both ERC20Detailed and ERC20Burnable are inheriting from IERC20.

:computer: Environment
Remix IDE
OpenZeppelin Contracts v2.5.0
Solidity 0.5.0

:1234: Code to reproduce

    pragma solidity ^0.5.0;

    import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC20/ERC20Detailed.sol";
    import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/ERC20Burnable.sol";

    contract GGCoin is ERC20Burnable, ERC20Detailed {
        
        address owner;
        
        constructor () public ERC20Detailed("GGCoin", "GGC", 2) {
            _mint(msg.sender, 100000);
            owner = msg.sender;
        }
        
        function mint(uint256 amount) public {
            require(msg.sender == owner);
            _mint(msg.sender, amount);
        }
        
    }

Is it possible to inherit from both ERC20Detailed and ERC20Burnable, without getting this error? Maybe I have to call the constructor differently?

1 Like

Hi @Lennard_Mulder,

Welcome to the community :wave:

It is definitely possible to inherit from ERC20Detailed and ERC20Burnable. (You could also inherit from ERC20Mintable).

Using Deploy a simple ERC20 token in Remix as a basis.

A simple token that is burnable could be as follows:

:warning: Please note this code hasn’t been tested or audited

pragma solidity ^0.5.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC20/ERC20Detailed.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC20/ERC20Burnable.sol";

contract Token is ERC20, ERC20Detailed, ERC20Burnable {

    constructor () public ERC20Detailed("Token", "TKN", 18) {
        _mint(msg.sender, 1000000 * (10 ** uint256(decimals())));
    }
}

Hi @Lennard_Mulder,

Just wanted to check how you got on with creating a burnable and detailed ERC20?