I have two contracts with variables and functions that each should need to reference/call. I would prefer to separate the contracts, as different user groups would be accessing each. Can two contracts import each other? Or is there an order of operations -so to speak- wherein only one contract can be dependent on another?
1 Answer
Yes, you can compile two contracts that call each other. For example,
contract InterfaceOfA {
function f(uint) returns (uint);
}
contract InterfaceOfB {
function g(bool) returns (bool);
}
contract A is InterfaceOfA {
InterfaceOfB b;
function f(uint _input) returns (uint) {
b.g(true);
return 3;
}
}
contract B is InterfaceOfB {
InterfaceOfA a;
function g(bool _input) returns (bool) {
a.f(0);
return false;
}
}
-
1Functionally, is there any difference if the two contracts modify each other in the same .sol file vs. importing and modifying each other from separate .sol files? Nov 15, 2016 at 16:30