Some contents of this article are based on Cryptozombies’s source code, based on GPL-3.0

Lesson 2

Chapter 1: Lesson Overview

Chapter 2: Mappings and Addresses

  • Address: an address of account
    • it is a unique identifier that points to that account
  • Mappings: a way of storing organizaed data in Solidity
    • mapping is key-value store
        mapping (address => uint) public accountBalance
      

Chapter 3: Msg.sender

  • msg.sender: refers to the address of the person who called the current function
    • it gives the security of the Ethereum Blockchain
    • only way to modify someone else’s data is to steal the private key
    • mappingFunction[key] = value;

Chapter 4: Require

  • In this trivial example, require is used to make each player can only call a function once
    • require(condition);
    • e.g., require(totalCount[msg.sender]<=2);

Chapter 5: Inheritance

  • Make manageable contract, by organizing and making inheritance
  • contract childContract is parentContract

Chapter 6: Import

  • import "directory/of/file/fileName.sol";

Chapter 7: Storage & Memory

  • Storage: permanently stored on the blockchain
  • Memory: temporary stored, and erased between external functions

Chapter 8: Zombie DNA

  • Keep examine and understand our structures and mappings

Chapter 9: More on Function Visibility

  • private, public, internal, external
  • internal: same w/ private, except that it is accesssible to contracts that inherit from this conctract
  • external: same w/ public, except that it can only be called outside the contract

Chapter 10: What Do Zomibes Eat?

  • interface: we need to define an interface, to talk to another contract that we don’t own
    • we decalre the funcion we want to interact with
    • we do not dfine the function bodies

Chapter 11: Using an Interface

Chapter 12: Hanling Multiple Return Values

  • 리턴값 갯수와 순서를 맞춘다
  • 순서대로 A, B, C 3개가 리턴되지만 C만 필요한 경우: (,,C) = multipleReturns();

Chapter 13: Bonus: Kitty Genes

  • Remember keccak256(abi.encodePacked(value))