My second smart contract! here are my notes…
Introduction
In my last post (LINK) I shared my personal notes about the first experience of programming a smart contract using solidity. Now in this opportunity I'll share the solutions of my "future tasks" that I mentioned there:
- How can the parent add more kids to the smart contract? (I realized how funny could be this question after seeing the first comment of that post. It made me laugh too)
- How can the parent add more balance to the kids
Smart Contract
The idea behind this smart contract consist in having a parent that wants his multiple kids to withdraw the money deposited after certain date. You can check the code here: LINK
Notes:
- We can use mapping(_key_type_=>_value_type_) to link data between different object types. In this case there is a link between a kid address and the amount available to withdraw
- Currently there's not option to check is a key is already in the map but this can be achieve by checking the supposed value
- In my journey of this development I came across with the "Smart Contract Security". I recommend to take a look at this before deploying any smart contract into the real world (I didn't know that smart contracts can be attacked)
- Remember to update internal data before making any external calls. This avoids reentrancy attack
Doubts:
- Why payable(_address_).transfer(_amount_) does not call the fallback function and msg.sender.call.value(_amount_) does?
submitted by /u/bloodkn07
[link] [comments]