2

I am trying to create a contract that has an instance of two other contracts. I am unable to create it. It keeps running out of gas even if I increase it to 999999999999999999999999999.

If I comment the functions that call functions in the other two contracts, it gets created, otherwise it doesn't.

Is there a way around it? How do contracts that use other contracts get created??

3
  • Could you add the code perhaps? Commented Apr 22, 2018 at 15:21
  • 1
    Sounds like you have large contracts or you are doing a lot of processing in the constructor.
    – gisdev_p
    Commented Apr 22, 2018 at 16:18
  • Another possibility is some of the child contracts throws an exception, this consumes all available gas so it doesn matter how much you assign.
    – Ismael
    Commented Apr 22, 2018 at 18:39

1 Answer 1

0

I assume you are attempting to create this on a private blockchain. The maximum gas allowed per block is 5.4m. You might be running into this limit.

7
  • I am using Remix while testing .. is it related in any way?
    – Haya Raed
    Commented Apr 22, 2018 at 15:13
  • I don't know. Could you try commenting out only one of the calls to the other contract and then check what the consumed gas for that call is? I would also like to know how much gas you consume when you do not call any other contract. Commented Apr 22, 2018 at 15:19
  • 1
    Without a call to any contract: transaction cost 1765920 gas execution cost 1306380 gas, If I keep only a call to one of the contracts it works with 2 functions and the gas is transaction cost 3843570 gas execution cost 2884534 gas if for both contracts it does not.
    – Haya Raed
    Commented Apr 22, 2018 at 15:30
  • With those numbers, it looks to me like you are exceeding the block limit for gas when calling both contracts. As I mentioned above, the limit is 5.4 million gas. You probably need to rewrite the contract such that it uses less gas. I don't think there exists another solution. Writing to storage (the permanent memory of a contract) is very expensive. If you can reduce the amount of times that you write to storage and reduce the data that you need to store permanently, you might be able to get your contract to work Commented Apr 22, 2018 at 16:08
  • do u mean by permanent memory of a contract .. when i create variables? what is the difference between writing to storage and data stored permanently
    – Haya Raed
    Commented Apr 22, 2018 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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