0

hope you can assist.

I have this very basic template setup, where contract TokenVote should simply store some data on the SimpleStore contract (Sort of eternal storage)

Yet my code always runs out of gas. What's wrong with my approach?

pragma solidity ^0.4.18;

contract ABSTRACTING {
    function addToWhitelist(address _ad) public;
}

contract SimpleStore {

    address[] public UserList;

    function addToWhitelist(address _ad) public {
        UserList.push(_ad);
    }
}

contract TokenVote {

    ABSTRACTING tokenContract;

    constructor(address token) public {
        tokenContract = ABSTRACTING(token);
    }

    function doStuff () public  {
        tokenContract.addToWhitelist(msg.sender);
    }

}
  • To begin with, change contract ABSTRACTING to interface ABSTRACTING and contract SimpleStore to contract SimpleStore is ABSTRACTING. – goodvibration Sep 18 '18 at 12:40
  • BTW, AFAIK, the constructor keyword is supported from solidity 0.4.21 onward, while you seem to be on solidity 0.4.18. – goodvibration Sep 18 '18 at 12:42
  • 1
    This exact code runs fine for me in Remix. I deployed SimpleStore first, then passed the resulting address to the constructor when creating TokenVote, and then I called doStuff. My gas limit was set to 3,000,000 for all transactions. – user19510 Sep 18 '18 at 13:05
  • @smarx You're right. In remix it works. Somehow on EthFiddle it runs out of gas. Damm. – De ruige Sep 18 '18 at 13:12
  • 1
    I see the same error on EthFiddle, but I don't see a good way to debug. – user19510 Sep 18 '18 at 13:17
0

Solved - It seems to be a bug in Ethfiddle.

@smarx pointed out that it worked in Remix without issues.

-1

Here are some ways to check and overcome the problem:

check if you really need everything you inherit put a higher gasLimit to your truffle.js config, try gas: 7492052, which is higher than the value in Truffle's defaults, and than in Rinkeby testnet. use optimizer settings to make bytecode slimmer and deploy cheaper if the above doesn't let you deploy and at least see your actual deploy cost, try commenting some functionality out and trying local deploy without something if the steps above show that you really need this much code and more, you can chop it in parts and deploy some of it as libraries or as separated contracts, one addressing another, depending on what fits you best. Hope it helps, that's basically my own trial-and-error conspectus on the matter.

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.