1
contract Test {
    constructor() public payable {

    }
}
contract MyContract {
    constructor() public payable {
        Test test = new Test();
    }
}

How do I pay the Test contract's constructor?

4
  • You should describe how you are deploying it! Commented May 28, 2020 at 13:47
  • from the contract
    – Noah Bergh
    Commented May 28, 2020 at 14:28
  • You're deploying the contract from itself? Very nice! Please explain exactly what off-chain tool you are using (e.g., web3.js, web3.py, Remix IDE, etc). And please share the relevant code along with this explanation! Commented May 28, 2020 at 14:45
  • Im using web3.js I know how to pay the first constructor but not the second
    – Noah Bergh
    Commented May 28, 2020 at 14:57

1 Answer 1

1

If you want to pass exactly what you've received:

Test test = (new Test).value(msg.value)();

If you want to pass, for example, half of what you've received:

Test test = (new Test).value(msg.value / 2)();

If you want to pass, for example, a constant value of 100 wei:

Test test = (new Test).value(100)();

Of course, you'll need msg.value >= 100 in order for that one to work.

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.