I am attempting to modify the contract below; the way it is set up at the moment is so that the contract can be deployed, and then anytime a user wants to create a campaign, they can do so without redeploying the entire contract.

What I am trying to do is create a scenario whereby a user can create a company(token) and then create campaigns under the banner of that company.

My question is; can I use the Factory function to create a parent/Child type function?

Note: I have attempted to copy and paste a child contract and then import it, however this didn't work and I wasn't really sure what I was supposed to do with the contract.

Thank you, any help greatly appreciated.

pragma solidity ^0.4.17;

    contract CampaignFactory {
    address[] public deployedCampaigns;

    function createCampaign(uint minimum) public {
        address newCampaign = new Campaign(minimum, msg.sender);

    function getDeployedCampaigns() public view returns (address[]) {
        return deployedCampaigns;

    contract Campaign {
    struct Request {
        string description;
        uint value;
        address recipient;
        bool complete;
        uint approvalCount;
        mapping(address => bool) approvals;

    Request[] public requests;
    address public manager;
    uint public minimumContribution;
    mapping(address => bool) public approvers;
    uint approversCount;

    modifier restricted() {
        require(msg.sender == manager);

    function Campaign(uint minimum, address creator) public {
        manager = creator;
        minimumContribution = minimum;

    function contribute() public payable {
        require (msg.value > minimumContribution);

       approvers[msg.sender] = true;

    function createRequest(string description, uint value, address recipient)
    public restricted
        Request memory newRequest = Request({
           description: description,
           value: value,
           recipient: recipient,
           complete: false,
           approvalCount: 0


    function approveRequest(uint index) public {
        Request storage request = requests[index];


        request.approvals[msg.sender] = true;


    function finalizeRequest(uint index ) public restricted {
        Request storage request = requests[index];

        require(request.approvalCount > (approversCount / 2));

        request.complete = true;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.