1

I'm currently trying to create instances of a smart contract via a clone factory. The problem is, that I'm not able to send a value to the init function of the smart contract I'm trying to instantiate. Here is a example:

TestContract.sol

// SPDX-License-Identifier: MIT
pragma solidity >0.4.23 <0.9.0;

contract TestContract {
    string testmessage;

function init(
    string memory _testmessage
) public payable {
    require(msg.value > 0, "The contract has to have at least a value");
    testmessage = _testmessage;
}

TestContractFactory.sol

// SPDX-License-Identifier: MIT
pragma solidity >0.4.23 <0.9.0;
import "./TestContract.sol";
import "./CloneFactory.sol";

contract TestContractFactory is CloneFactory {
    address public testContractAddress;
    address[] public clonedTestContracts;

event TestContractCreated(address newTestContract);

constructor(address _testContractAddress)
{
    testContractAddress = _testContractAddress;
}


function createTestContractAddress(
    string memory testmessage
) public payable {
    address clone = createClone(testContractAddress);
    TestContract(clone).init(testmessage);
    clonedTestContracts.push(clone);
    emit TestContractCreated(clone);
}

}

So when I try to instantiate a TestContract via the Factory in Remix with the value of 1 Ether, I get the message "The contract has to have at least a value". Does someone know why this happens? I was only able to find examples that use normal factories and not clone factories.

2
  • I believe the answer to the above question will help you out. I assume in your testing you're sending ETH with the call to createTestContractAddress. You also need to send the ETH with the call to init, you can see how to do that in the answer to the above question. Let me know if you need more guidance
    – natewelch_
    Jan 19, 2023 at 15:22
  • 1
    The answer in the question you provided was exactly what i needed. Thank you! Jan 19, 2023 at 15:31

0