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 have deployed Project1 inside of Project2.sol file. And also I have been using a struct which is in Project2 from Project1.sol file.
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;
applepies.push();
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 is 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?
function createProject{
throws syntax error. It's valid either in some very old version, or you didn't copy-paste correctly the parenthesis (old Solidity version) and visibility modifier (public
,external
, ...). Can you also correct this? – Cotangent