1

I'm working on a Dutch Auction style ICO contract and I'm currently trying to migrate an early stage of my ERC20 contract to test the basic features (does it have the correct name, symbol, and decimals). The contract compiles but I can't migrate it since it is an "abstract contract". My token contract inherits from ERC20Detailed, the Open Zeppelin contract, which in turn inherits from the IERC20 interface contract. What can I do to fix this? I tried having my Token contract also inherit from ERC20 the base contract but it said the identifier was already declared. I see the possible responses from the Truffle terminal output but I'm curious why my implementation won't work and would love some more help understanding Solidity interfaces and abstract contracts.

What can I do to fix this? I tried having my Token contract also inherit from ERC20 the base contract but it said the identifier was already declared.

pragma solidity ^0.5.8;

import "node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";


contract Token is ERC20Detailed{
    constructor(string memory _name, string memory _symbol, uint8 _decimals)
        ERC20Detailed(_name, _symbol, _decimals)
        public
        {

        }


}

Output from Bash terminal

"Token" is an abstract contract or an interface and cannot be deployed. * Import abstractions into the '.sol' file that uses them instead of deploying them separately. * Contracts that inherit an abstraction must implement all its method signatures exactly. * A contract that only implements part of an inherited abstraction is also considered abstract.

1 Answers1

5

If you look closer at ERC20Detailed contract, you will notice ERC20Detailed is IERC20. In simple English, it says "this ERC20Detailed inherits all functionalities from IERC20".

Now, take a look at IERC20 contract. You will notice all functions there were terminated with ; with no logic. This is what we call as Abstract Contracts in Solidity.

Your front-end contract (Token) wants to use all functions from:

  • ERC20Detailed - has all implementations in its file
  • IERC20 (via ERC20Detailed) - doesn't has implementations in its file

That's why you are getting This contract does not implement all functions and thus cannot be created error.

To solve this problem, try this approach:

pragma solidity ^0.5.8;

import "path-to/ERC20/ERC20.sol";
import "path-to/ERC20/ERC20Detailed.sol";

contract Token is ERC20, ERC20Detailed {
   constructor(string memory name, string memory symbol, uint8 decimals) 
    ERC20Detailed(name,symbol,decimals) 
    public {
        // TODO    
    }
}

The ERC20 contract has all implementations for IERC20 contract. You can give it a try in Remix first this code below:

pragma solidity ^0.5.8;

import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";

contract Token is ERC20, ERC20Detailed {
   constructor(string memory name, string memory symbol, uint8 decimals) 
    ERC20Detailed(name,symbol,decimals) 
    public {
        // TODO    
    }
}

enter image description here

Zulhilmi Zainudin
  • 9,017
  • 12
  • 62
  • 98
  • Thank you for your insightful response. When I try this above method VSCode is underlining my ERC20Detailed import and telling me "Identifier already declared" – Christian Volckaert Jul 13 '19 at 17:39
  • Whichever import statement I make, the second line is "identifier already declared". and I get this error message during compilation "The previous declaration is here: interface IERC20 { ^ (Relevant source part starts here and spans across multiple lines)." When I try what you posted on remix it all works fine. Is there an issue with the interface, or is there some issue with my local methods of importing the Open Zeppelin libraries? – Christian Volckaert Jul 14 '19 at 03:11
  • 1
    FOUND THE ISSUE. When I was compiling my contracts I noticed that IERC20 was being compiled twice. I had ERC20 and ERC20Detailed importing the contract but I gave two different filepaths. By changing them to the same filepath IERC20 was being imported only once and everything compiles cleanly. – Christian Volckaert Jul 14 '19 at 03:28
  • Awesome. Really appreciate if you could upvote and accept my answer. :) – Zulhilmi Zainudin Jul 15 '19 at 06:19