0

hello guys I am a beginner. I would like to make a function for create a contract.

I found a example on the internet but gives me an error so I dont know what should I do.

Anyone can help me ?

pragma solidity ^0.5.0;

contract Product {
    Factory public factory;
    Product public reference;//**here's the error**
function Product(Product _reference, Factory _factory){
    reference = _reference;
    factory = _factory;
}

function haveFactoryCreateProductWithReferenceToThis() public {
    emit ProductCreated(factory.createNewProduct(this));
}

event ProductCreated(Product indexed product);
}

contract Factory{
    function createNewProduct(Product _reference) public returns (Product) {
        Product p = new Product(_reference, this);
        return p;
    }
}
1
pragma solidity ^0.5.0;

contract Product {
    Factory public factory;
    Product public x;
constructor(Product _reference, Factory _factory) public{
    x = _reference;
    factory = _factory;
}

function haveFactoryCreateProductWithReferenceToThis() public {
    emit ProductCreated(factory.createNewProduct(this));
}

event ProductCreated(Product indexed product);
}

contract Factory{
    function createNewProduct(Product _reference) public returns (Product) {
        Product p = new Product(_reference, this);
        return p;
    }
}

hey I make a small change and it's work now !

Not the answer you're looking for? Browse other questions tagged or ask your own question.