0

This is one of my parent contract (child factory contract) functions that creates a child contract. The function should be provided with 3 arguments

    function breed(uint _number, uint _amount, address payable _beneficiary) public payable {
        childDong _childdong = new childDong(_number, _amount, _beneficiary);
    }

And here is my child contract constructor function which gets created every time the above function gets called.

    constructor(uint _number, uint _amount, address payable _beneficiary) payable {
        _number = number;
        _amount = amount;
        _beneficiary = beneficiary;
    }

Every time I want to execute the breed function from the parent contract, I encounter this issue in the terminal. Does anyone how i can overcome this issue. error on remix terminal

Thanks in advance

7
  • Why is the child constructor also payable ? Do u want to send ether to the child contract !
    – Majd TL
    Jun 18 at 14:48
  • Not actually, I saw it somewhere. Do you think removing it gonna help? Jun 18 at 15:11
  • I thought primary calculations in the child contract would need some gas, because of this I was trying to send some ether along creating the child. Jun 18 at 15:30
  • When you have “payable” in the constructor then u should send extra ether to your contract and that is not the ether to pay the transaction fee. The transaction fee and gas is handled separately. How are u calling the contract ?
    – Majd TL
    Jun 18 at 18:11
  • 1
    About your last comment to make it maybe clearer :) The payable declaration has nothing to do with the gas that is consumed by your contract. Payable should be used when you want the user to explicitly send extra ether to the contract, those ethers are not used to pay the network fees and they will be owned by the smart contract and u need an additional function in the contract to spend them or they will get stuck there.
    – Majd TL
    Jun 18 at 18:21
0

Since the code is not complete (calling breed function), it is a bit difficult to find the root cause of this error. Moreover, I think the variable assignments in the constructor is not correct. In other words, an assignment statement causes the expression on the right-hand-side to be evaluated. If the left-hand-side is a variable, the value of the right-hand-side is assigned to that unevaluated variable. In your case, all values of "number, amount, and beneficiary" are "0, 0, and zero bytes20", respectively. The correct code is: (I do not think this correction would solve your main error):

constructor(uint _number, uint _amount, address payable _beneficiary) payable {
    number = _number;
    amount = _amount;
    beneficiary = _beneficiary;
}

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.