I have two different files which are Project1.sol and Project2.sol

Project2.sol is like:

import "./Project1.sol";
contract Project2{
    address newProject1Address =address(new Project1());

Project1.sol is like:

import "./Project2.sol";

contract Project1 is Project2{


I wanted to deploy Project1 in Project2.sol. And also I have been using a struct which is in Project2 from Project1.sol file. That's why I used "is" in the code.

However, I got an error which is "definition of base has to precede definition of derived contract." for this line: contract Project1 is Project2{

After I checked the error on the internet, there were solutions for two contracts and one file. However, I had two files.

I merged these two contracts in a file.

This is what I did:

pragma solidity >=0.7.0 <0.9.0;

contract Project2{

        Apple[] public applepies;
        struct Apple{
             string name;
             mapping (address => bool) applepie;

        function createProject() external{
             address newProject1Address =address(new Project1(msg.sender));

             uint idx = applepies.length;
             Apple storage newProject = applepies[idx];



contract Project1 is Project2{
        address public creator;

        constructor (address creator1){
             creator= creator1;

        function getDetails(uint index) public{
             Apple storage newv= applepies[index];
             //require(newv.applepie = msg.sender);

Then, I could not deploy Project1 from Project2. When I do that, this the error which I got, "circular reference for contract creation(cannot create instance of derived or same contract)" on this part address newProject1Address =address(new Project1());

What should I do? What is your suggestions?

Your Answer

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

Browse other questions tagged or ask your own question.