3

Im building a contract that uses two contracts that both use the ERC721 zeppelin contract, when I import the two as such:

import nonFungableWidthAddedFunctionality1.sol;
import nonFungableWidthAddedFunctionality2.sol;

I get the following error:

$PATH DeclarationError: Identifier already declared.
import "./../nonFungableWidthAddedFunctionality2.sol";
^--------------------------^
$PATH The previous declaration is here:
contract ERC721 {
^

Both of these contracts need the ERC721 implementation since they are also used separately.

3
  • 1
    If you just need to call the ERC721 functions from your third contract, you can just import the ERC721 definition, instead of the individual token contracts. Aug 1, 2018 at 10:51
  • But both the tokens have different implementations and augmentations of the standard ERC721 protocol.
    – jasper
    Aug 1, 2018 at 11:09
  • 1
    Your solution did work after looking through the ERC721 interface a bit more careful, thank you!
    – jasper
    Aug 1, 2018 at 12:14

2 Answers 2

1

You are declaring contract ERC721 more than once, thus the error.

Essentially, you're doing this:

contract Contract1 {
}

contract Contract1 {
}
0

In my case it was caused by collisions between IERC20.sol from an openzeppelin module and my own IERC20.sol file that I had in my interfaces folder. For my own smart contracts I was using my own IERC20.sol, while some of my imported contracts were using the IERC20.sol file found in the openzeppelin module.

As a simple solution I removed my personal IERC20.sol file and instead only used the IERC20.sol interface provided by the openzeppelin module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.