0

I have written a simple blog post contract in solidity.

contract  Blog {
    uint256 counter ;
    struct BlogPost {
        uint256 id;
        string title;
        string content;
        address user;
    }
    BlogPost[] public posts;
function createPost(string calldata _title, string calldata _content) external {
    counter+=1;
    BlogPost memory newPost;
    newPost.id=counter;
    newPost.title=_title;
    newPost.content=_content;
    newPost.user=msg.sender;
    posts.push(newPost);
}

}

I have deployed my contract on a localnode. I have a few questions on what's happening here:

  1. When I deploy the contract, how and what is getting stored on the blockchain?
  2. When I call the createPost() function, where is the array of structs(BlogPost struct) getting stored on the blockchain? Is it stored on a single block or shared between mulitple blocks?
  3. When I call the createPost() function, what happens on the blockchain?
  • here is all you need to know : https://github.com/ethereumbook/ethereumbook/blob/develop/13evm.asciidoc and it's a possible re asking of : https://ethereum.stackexchange.com/questions/23351/how-contract-data-is-stored-in-blockchain – Torof Nov 23 '22 at 10:45
  • yah i checked that question, but it wasn't as intuitive as mine – Bhargav Nov 23 '22 at 10:48
  • Like I said, you have all the answers to your question in the EVM part of the ethereum_book – Torof Nov 23 '22 at 10:53

1 Answers1

-1

There is that very useful article: https://jeancvllr.medium.com/solidity-tutorial-all-about-structs-b3e7ca398b1e

And you can also use the debugger on remix to see what's happening to the storage of your smart contract when you call 'createPost()'.

Hope this helps!

Olivier Demeaux
  • 1,957
  • 2
  • 8
  • 16