2

I want to create another contract in a contract function call and pass the associated ether into that new contract. Seems like it makes sense to want to do but...

Why doesn't this work?

contract B {
    uint x;
    function B(uint a) payable {
        x = a;
    }
}


contract A {
    function createAndPassAmount(uint arg, uint amount) payable {
        B newD = new B.value(amount)(arg);
    }
}
3

You need parentheses around new B (see below):

contract A {
    function createAndPassAmount(uint arg, uint amount) payable {
        B newD = (new B).value(amount)(arg);
    }
}
|improve this answer|||||

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.