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;
    }
}

closed as too broad by Ha ĐANG, alberto, shane, Majd TL, Crissi Mariam Robert Jul 24 at 12:33

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

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.