0

I tried doing

address NewContract = new SomeTest.value(1 ether)();

But this yields a syntax error.

I try to call the payable constructor of a new contract with ether. What is the syntax for this?

1

Try using the below syntax (ensure that the SomeTest constructor is marked payable):

pragma solidity ^0.4.24;

contract SomeTest 
{
    constructor() public payable {}
}

contract A 
{
    address newContract;

    function test() public 
    {
      //construct a new SomeTest with 1 ether
      newContract = (new SomeTest).value(1 ether)(); 
    }
}

Source: http://solidity.readthedocs.io/en/develop/frequently-asked-questions.html#how-do-i-initialize-a-contract-with-only-a-specific-amount-of-wei

TLDR: encapsulate in parentheses like this (new SomeTest).value(1 ether) .

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.