trufflesuite / ganache-ui

Personal blockchain for Ethereum development
https://www.trufflesuite.com/ganache
MIT License
4.67k stars 806 forks source link

Unable to call function from another contract, that is already deployed on ganache #788

Closed tadejrola closed 5 years ago

tadejrola commented 6 years ago

I have 2 contracts.

Contract1.sol

pragma solidity ^0.4.24;

contract Contract1{

    event Call(
        string data
    );

    function call(string _data) public {
        emit Call(_data);
    }
}

Contract2.sol

pragma solidity ^0.4.24;
import "./Contract1.sol";

contract Contract2 {

    Contract1 public _contract1;

    constructor(address _add){
        _contract1=Contract1 (_add);
    }

    function sendData() public {
        _contract1.call("data");
    }
}

Everything works perfectly fine using:

But it does not work with custom RPC using Ganache v1.1.0. When i try to call sendData() from Contract2.sol, the transaction reverts.

mikeseese commented 6 years ago

Hey @tadejrola I'm not sure if this is your issue, but right off the bat it looks like there's a typo: Contract2 public _contract2; should be Contract1 public _contract1; and _contract2=Contract2 (_add); should be _contract1=Contract1 (_add); and _contract2.call("data"); should be _contract1.call("data");

mikeseese commented 6 years ago

Frankly, I'm not sure how this would work either way. It's almost like you would have an infinite loop during construction/deployment with your current code (contract2 has a contract2 which is built on construction, and therefore an infinite construction of contract2's).

Further Contract2.sol doesn't have a function call as that's in Contract1.sol and you don't extend Contract1.

Am confused why it would work :D

tadejrola commented 6 years ago

Thanks for your answer @seesemichaelj Ohh it was a typo. I fixed the example. But as you can assume, this is only prototype of my original code. And i still have no idea, why transaction reverts using ganache.

mikeseese commented 6 years ago

Does it still revert after using the updated source code @tadejrola?

I could see it reverting because of an Out Of Gas error because of this endless loop you had, as well as calling a function that didn't exist

tadejrola commented 6 years ago

Yes, it still reverts @seesemichaelj . Actually my original code didnt have typo. Only this, example code.

Gas is not the problem, because, as i said it works perfectly fine on Ropsten.

fbalwy commented 5 years ago

I've got the same problem :(

davidmurdoch commented 5 years ago

This should now be fixed in our latest beta: https://github.com/trufflesuite/ganache/releases/tag/v2.0.1-beta.0 Let me know if you have any issues or if the fix doesn't work for you.