1. Payable

Visibility modifier

  • private: only callable from other functions inside the contract
  • internal: like private, but also called by contract that inherit the contract
  • external: can only be called outside the contract
  • public: can be called anywhere

state modifier

  • view: no data will be saved/changed
  • pure: not save data to blockchain, and also doesn’t read from the blockchain

2. Withdraws

contract GetPaid is Ownable {
  function withdraw() external onlyOwner {
    address payable _owner = address(uint160(owner()));
    _owner.transfer(address(this).balance);
  }
}
  • address가 address payable이어야 Ether를 전송할 수 있다
  • uint160 variable은 address payable로 명시적 형변환이 가능하다

3. Zombie Battles

4. Random Numbers

5. Zombie Fightin’

6. Refactoring Common Logic

7. More Refactoring

  • modifier는 2개 이상 사용 가능하다 –> 함수 선언자 맨 마지막에 띄어쓰기로 구분해서 적으면 된다

8. Back to Attack!

9. Zombie Wins and Losses

10. Zombie Win

11. Zombie Loss

12. Wrappint It Up

13. Lesson 4 Completed