0

I wrote two contract, the first Contract1 have a simple function, and the second Contract2 's constructor receive a Contract1 address and call the simple function.

I create Contract1 address, then use this address to create Contract2.

I found I can create Contract2 's address right in remix javascript vm, but fail in private net.

pragma solidity ^0.4.18;

contract Contract1{
    function simple() external view returns (bool) {
        return true;
    }
}

contract Contract2{
    bool public result;
    constructor(address contract1Address) public {
        Contract1 contract1 = Contract1(contract1Address);
        result = contract1.simple();
    }
}
1

I have most of the answer.

You pragma solidity ^0.4.18; is untrue. You are using the constructor format that was introduced with 0.4.22, so it does not compile with 0.4.18 as it claims it does.

As luck would have it, the issue seems to be related to the constructor. It's very new. Someone else reported that it creates a function signature that exactly matches the fallback function and that caused an unrelated issue. I suspect something similar is happening here.

What I found is that the contract compiles and works just fine when it's adjusted to the style of and compiled with an earlier compiler. I set it to 0.4.19 to match up with recent Truffle and I removed ^ to eliminate possible inconsistency since we can see the exact compiler is sure to be a problem.

Note that 0.4.19 does not understand constructor and that could be an issue with your deployment process.

pragma solidity 0.4.19;

contract Contract1{
    function simple() external view returns (bool) {
        return true;
    }
}

contract Contract2{
    bool public result;

    function Contract2(address contract1Address) public {
        Contract1 contract1 = Contract1(contract1Address);
        result = contract1.simple();
    }
}

Works as expected.

Hope it helps.

  • 1
    I tried it works fine as expected – rahul saini May 3 '18 at 6:07

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.