DeclarationError when inheriting GSNRecipient

:computer: Environment

localhost
Truffle 5.1.9
Node 11.12
solc 0.5.5
@openzeppelin/contracts 2.4.0
@openzeppelin/network 0.4.2

:memo:Details

My contract inherits from ownable, pausable, ERC721Full, ERC20 and recently GSNRecipient. I don’t use the initializable pattern so all my constructors are still constructors. I started getting this compilation error after adding GSNRecipient:

/MyContract.sol:6:1: DeclarationError: Identifier already declared.
import “…/node_modules/@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol”;
^-----------------------------------------------------------------------------------------------^
/C/Workspace/my-dapp/node_modules/@openzeppelin/contracts/GSN/Context.sol:13:1: The previous declaration is here:
contract Context {
^ (Relevant source part starts here and spans across multiple lines).

I understand that this is happening because Context is being declared in many of the contracts my contract is inheriting from but I am unsure about how to fix this. Do I keep a copy of all these contracts and remove Context inheritance from all so that only one remains?

1 Like

Hi @pwn0,

Welcome to the community :wave:

OpenZeppelin Contracts is for regular (non-upgradeable) contracts while OpenZeppelin Contracts Ethereum Package is an official fork of OpenZeppelin Contracts that has been modified to use initializers instead of constructors so that they can be used with upgradeable contracts.

I was curious to why you need to import both OpenZeppelin Contracts and OpenZeppelin Contracts Ethereum Package. I assume this is the cause of your error. You mentioned that you are not using initializers and are only using constructors, so you could just use OpenZeppelin Contracts.

I noticed that you are importing OpenZeppelin Contracts 2.4. The latest version using Solidity 0.5 is OpenZeppelin Contracts 2.5.1

I was also curious why your contract inherits from ERC721 and ERC20. Are you able to share any details?

Hi @pwn0,

OpenZeppelin Contracts Ethereum Package v3.0 has been released.