목록Block Chain (22)
2020.코딩일지
오버플로우 0.8버전 기준으로 이전과 이후를 비교 // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 overflow revert // overflow: 0~255 -> 257 -> 1 library SafeMath { //0~255; 0.8이전버전에서는 합이 255가 넘으면 오버플로우가 발생. // 0.8이후버전에서는 255가 넘으면 에러발생 // a:1 b:255 -> a+b= 256 -> (오버플로우로 0이됨)0 >= 1 -> false // a:0 b:256 -> b에서 uint8이라 에러발생 function add(uint8 a, uint8 b) internal pure returns (uint8) { require(a+b >= a, "Sa..
enum // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 =0.7.0
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0
payable // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 =0.7.0 = msg.value, "Your balance is not enough"); _to.transfer(msg.value); emit SendInfo(msg.sender, (msg.sender).balance); //event로 전송하고 남은 잔액이 나옴 } function checkValueNow() public { emit MyCurrentValue(msg.sender, msg.sender.balance); } function checkUserMoney(address _to) public{ emit CurrentValueOfSomeone(msg.sender, _to, _..
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 25, "You are not allowed to pay for the cigarette"); return "You payment is succeeded"; } function onlyAdults32(uint256 _age) public pure returns(string memory) { require(_age>25, "You are not allowed to pay for the cigarette"); return "Your payment is succeeded"; } //위의상황을 아래와같이 modifier로 개선------------------------------------------- m..
return // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 =0.7.0
error // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 19,"You are not allowed to pay for the cigarette" ); return "Tour payment is acceeded"; } } try-catch문 // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0
if문 // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 =0.7.0
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 Character) public CharacterMapping; Character[] public CharacterArray; //필수파라미터 입력 / returns에 //..왜가스비가 안드는거지? function createCharacter(uint256 _age, string memory _name, string memory _job) pure public returns(Character memory) { return Character(_age, _name, _job); } function createCharacterMapping(uint256 _key, uint256 _age, string m..
1. mapping // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 uint256) private ageList; function setAgeList(uint256 _index, uint256 _age) public { ageList[_index] = _age; } function getAge(uint256 _index) public view returns(uint256) { return ageList[_index]; } //------------------------------------------------ mapping(string=>uint256) private priceList; function setPriceList(string mem..