[Solidity] 230621 study
1. Payable
Visibility modifier
private: only callable from other functions inside the contractinternal: likeprivate, but also called by contract that inherit the contractexternal: can only be called outside the contractpublic: can be called anywhere
state modifier
view: no data will be saved/changedpure: 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개 이상 사용 가능하다 –> 함수 선언자 맨 마지막에 띄어쓰기로 구분해서 적으면 된다