Last active
January 30, 2023 19:06
-
-
Save rkotov93/4ea77568ec65bb4e010d2499db575b77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.8.17; | |
contract Contract1 { | |
Contract2 public contract2; | |
constructor() { | |
contract2 = new Contract2(address(this)); | |
} | |
function foo() public pure returns (string memory) { | |
return "bar"; | |
} | |
} | |
// In this case it fails | |
contract Contract2 { | |
Contract1 contract1; | |
constructor(address _contract1) { | |
contract1 = Contract1(_contract1); | |
contract1.foo(); | |
} | |
} | |
// In this case everything works fine | |
contract Contract2 { | |
Contract1 contract1; | |
constructor(address _contract1) { | |
contract1 = Contract1(_contract1); | |
} | |
function bar() public view returns(string memory) { | |
return contract1.foo(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment