contract Test {
    constructor() public payable {

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

How do I pay the Test contract's constructor?

  • You should describe how you are deploying it! – goodvibration May 28 at 13:47
  • from the contract – Noah Bergh May 28 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! – goodvibration May 28 at 14:45
  • Im using web3.js I know how to pay the first constructor but not the second – Noah Bergh May 28 at 14:57

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.

| 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.