0

I have a problem with simple solidity code in Remix. Even I give 10 ETH(testnet) to the contract C but it doesn't work. Error is:

transact to C.makeContract errored: gas required exceeds allowance or always failing transaction

pragma solidity ^0.4.21;

contract A{
    uint public a;
    function setA(uint _a){
        a = _a;
    }
    function getData() constant returns (uint){
        return a;
    }
}

contract B is A {
    function getData() constant returns (uint) {
        return a * 10;
    }
}

contract C {
    A[] internal c;
    function () payable {}
    function makeContract() returns (uint, uint){ //I have no idea why     this function occurs error
        c.length = 2;
        A a = new A();
        a.setA(1);
        c[0] = a;
        B b = new B();
        b.setA(1);
        c[1] = b;
        return (c[0].getData(), c[1].getData());
    }
}

Here is my solidity code. HELP ME PLZ!!

  • 1
    Ran it on remix just as you post it, and it works – Jaime Jul 27 '18 at 10:25
  • Code seems to be running fine using Remix. I even tried the various Run settings such as "Javascript VM", "Injected Web3" and "Web3 provider" . Works fine! Are you facing this error every time you run the code, or occasionally only? Are you using any tools in conjunction with Remix (Metamask?, Ganache?) – Bharat Mallapur Jul 27 '18 at 13:53
0

I think the problem is that your are calling C.makeContract with ether but your function is not payable.

Send your transaction without ether and it should be fine. You need to understand the difference between value and Gas limit.

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.