Skip to content

Instantly share code, notes, and snippets.

@rkotov93
Last active January 30, 2023 19:06
Show Gist options
  • Save rkotov93/4ea77568ec65bb4e010d2499db575b77 to your computer and use it in GitHub Desktop.
Save rkotov93/4ea77568ec65bb4e010d2499db575b77 to your computer and use it in GitHub Desktop.
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