0

Let's say that we have a parent smart contract which functions as a blueprint for a business marketplace which covers various use cases and each use case is defined in this parent smart contract, e.g. Pizzaria use case and its associated functionality/parameters. However, there might be more than one Pizzaria company part of the marketplace, so different parameters might be needed such as price etc.

How would one go about generating child smart contracts from a parent smart contract with different parameters?

2

Here's a really oversimplified scaffold to start with.

pragma solidity 0.4.19; 

contract Pizzeria {

    bool public isPizzaria;
    uint public param1;
    uint public param2;

    function Pizzeria(uint arg1, uint arg2) public {
        param1 = arg1;
        param2 = arg2;
    }

}

contract PizzeriaFactory {

    address[] public pizzeriaFactories;

    function createPizzeria(uint arg1, uint arg2) public returns(address newPizzeria) {
        Pizzeria p = new Pizzeria(arg1, arg2);
        pizzeriaFactories.push(address(p));
        return address(p);
    }

}

Hope it helps.

  • Quick question, couldn't the pizzeria contract logic, be part of the pizzariafactory contract logic? – NowsyMe Apr 14 '18 at 21:53
  • Your question specifically asked about parent/child contracts and (before I edited it away because it isn't recent, the new option). You can indeed construct a single contract that handles all concerns. This is an architectural choice. A single contract would contain a list of instances of pizzerias and the logic of pizzerias (not shown). Have a look over here for list-management scaffolds. ethereum.stackexchange.com/questions/13167/… – Rob Hitchens - B9lab Apr 14 '18 at 22:12
  • thanks for that reference, I've been looking for something like this for long!! – NowsyMe Apr 14 '18 at 22:46
  • Don't forget to give that post a vote so others can find it. ;-) Thanks. – Rob Hitchens - B9lab Apr 14 '18 at 23:00

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.