0

I want to spawn a child contract from a parent/owner contract. I would like the caller of the creating function on the parent contract to pay for gas and fee and also pass on the sent value (payable amount) to the child contract on creation.

pragma solidity ^0.4.25;

contract Child {
   string public a;
   constructor (string arg) public payable { 
       a = arg;
   }
}

contract Factory {
    constructor () public {}
    function createChild(string arg) public payable {
        address issueContract = (new Child).value(msg.value)(arg);
    }
}

Any idea why the transaction to Factory.createchild keeps failing when the value/payable amount passed is greater than 0 WEI? (it does only work when not value is passed at all ... )

Thanks a lot!

1

Hmmm ... something else going on here. When I run it in Remix, all is well.

Here, I've added events to report what's happening.

pragma solidity ^0.4.25;

contract Child {

   string public a;

   event LogCreatedBy(address creator, string arg);

   constructor (string arg) public payable { 
       a = arg;
       emit LogCreatedBy(msg.sender, a);
   }
}

contract Factory {

    event LogCreatedChild(address sender, string arg, address created);

    function createChild(string arg) public payable {
        address issueContract = (new Child).value(msg.value)(arg);
        emit LogCreatedChild(msg.sender, arg, issueContract);
    }
}

And here it is in Remix to show it working. I sent 100 Wei. No issue.

enter image description here

Is it possible the issue is client-side?

Hope it helps.

  • Thanks Rob for looking at it. I had another go at it and it runs after I fixed up a typo in a pre-condition require(...) in the Factory call. Anyway thanks for putting me on the right path. – thierryx Nov 11 '18 at 2:43

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.