My first smart contract! What did I learn?
This post is about what I learned in the journey of my first smart contract development using solidity as the programming language. This is not a 100% super tutorial on how to develop smart contracts. If you are looking for one I was inspired by this : https://www.youtube.com/watch?v=MTC8BHrmrJA.
This info is like a story and notes of my brain trying to create its first smart contract. Please feel free to correct me or share a better explanation. I will really appreciate the feedback.
When I searched for "smart contracts development" I found many resources where they suggest to use the truffle framework but also some of them said that Remix was a good tool to start, so I went with this one (Remix.ethereum) why? because I wouldnt need to install NodeJS and truffle to achive my simple goal that was to create the SC and interact with it as easy as possible
The idea behind this smart contract consist in having a parent that wants his kid to withdraw the money deposited after certain date. You can check the code here: https://pastebin.com/1dF5dtpj
- Due to I am using solidity, in any smart contract I should define the compiler version. I do this in the first line of code where I write "pragma solidity = 0.8.1;"
- To store an address I define a variable as address type. In this case I'll store the parent and kid addresses
- The person who deploy the smart contract is the parent so that is why in the constructor I set the parent address to the one who send the transacion (msg.sender)
- What does it mean having external in a function? So after some reading I understood that external is a type of visibility that solidity functions could have. Also, external functions cannot be called internally and they can be cheap (in terms of gas) due to the data is not copied to memory. These are some good links:
- What does it means having payable in a funcion? It means that the smart contract can recieve some ether throught this function, the ether sent in the transacion will be added to the balance of the smart contract. If I sent ether to a non payable function it will throw an error. I found this in stackexchange and I liked it. https://ethereum.stackexchange.com/questions/20874/payable-function-in-solidity/32621
- What about payable()? I could say that in ethereum there are 2 types of address: normal address and payable address. We can only send ether to payable address so payable() will convert the normal address into a payable address
- I can view how much ether the smart contract has by address(this).balance
- How can the parent add more kids?
- How can the parent add more balance to the kid