1

I would like to create a sort of tree type hierarchy of contracts. Think of it like a multi-level-marketing scheme -- the person at the top will receive X. For each of the k people he recruits he agrees to give them a payout alpha*X / k .... given the condition that they recruit at least k more people to the same type of contract.

I would like the nodes to be transferable -- so someone could sell any of the payouts associated with node contracts to someone else if they like (I'm assuming this is true of all smart contracts? I'm new ethereum)

Could you point me towards how one would implement such a structure?

  • Yes. With programming only your imagination and skill to program are your limits. – Mikko Ohtamaa Jul 22 at 6:50
  • @MikkoOhtamaa GAS is also your limit. – MentatX Jul 22 at 7:10
  • Then you imagine eth 2.0 without gas limits :) – Mikko Ohtamaa Jul 22 at 15:09
1

What you're looking for is the factory contract storage pattern, and not a "recursive" smart contract. Recursion doesn't quite make sense here.

The idea is that you have a contract that can deploy contracts. Below is an example of a CampaignFactory contract that deploys Campaign contracts. What you'd want to do then is add a linked list feature to each new campaign.

You could add the Multi-level marketing aspect by allowing each additional Campaign to also have the functionality of the CampaignFactory, as well as have a variable like address creator that points back to the original creator.

It would then be pretty easy to send the MLM money 'up' the chain.

contract CampaignFactory {

    Campaign[] campaigns;
    address creator;
    mapping(address => Campaign[]) campaignsByOwner;

    function createCampaign(uint min_contrib) public {
        Campaign newCampaign = new Campaign(min_contrib, msg.sender);
        campaignsByOwner[msg.sender].push(newCampaign);
        campaigns.push(newCampaign);
    }

    function getAllCampaigns() public view returns (Campaign[] memory) {
        return campaigns;
    }

    function getCampaignByAddress(address creator) public view returns (Campaign[] memory) {
        return campaignsByOwner[creator];
    }
}
| improve this answer | |
  • 1
    Thank you, this is exactly what I needed. – user491880 Jul 23 at 0:42

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.