My Ethereum app consists of creating a post like on Facebook and people can like/comment on it. Should I create separate contract copy for every post or just one contract to deal with all posts?


You should store them all in one contract; there's no reason to create an arbitrary amount of contracts.

In Solidity, you can use a dynamically sized array to store all the posts. A simple example would be a contract like this:

pragma solidity ^0.4.17;

contract Facebook
    struct Post
        address sender;
        string text;
    Post[] public posts;
    function createPost(string text) public
        posts.push(Post(msg.sender, text));
  • Thank you. I got this. But I really want to know when do we create new contract for different things? In which case do we do that? – SHIVAM SETHI Sep 29 '17 at 18:25
  • @SHIVAMSETHI, Once a contract has been deployed on the blockchain, you can't change its source code. If you want to change it, you will have to deploy a new contract with different source code. – Jesbus Sep 29 '17 at 19:15

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.