Solidity

    [CryptoZombie] 1-5 ERC721 & Crypto-Collectibles

    🧡 ERC721 Token contract ERC721 { event Transfer(address indexed _from, address indexed _to, uint256 _tokenId); event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId); function balanceOf(address _owner) public view returns (uint256 _balance); function ownerOf(uint256 _tokenId) public view returns (address _owner); function transfer(address _to, uint256 _tokenId) publi..

    [CryptoZombie] 1-4 Zombie Battle System

    🧡 Payable 이더리움을 지불에 관여할 수 있는 함수 제어자이다. contract OnlineStore { function buySomething() external payable { require(msg.value == 0.001 ether); transferThing(msg.sender); } } 🧡 Random Numbers keccak256을 이용해 난수를 생성할 수 있다. uint randNonce = 0; uint random = uint(keccak256(now, msg.sender, randNonce)) % 100; randNonce++; uint random2 = uint(keccak256(now, msg.sender, randNonce)) % 100; https://share.cry..

    [CryptoZombie] 1-3 Advanced Solidity Concepts

    🧡 컨트랙트의 불변성 이더리움에 컨트랙트를 배포하면 이 컨트랙트를 다시는 수정할 수 없다. 내가 최초로 배포한 컨트랙트는 블록체인 상에 영구적으로 존재한다. 즉, 만약 컨트랙트에 취약점이 존재해도 배포 이후에는 고칠 수가 없다. 🧡 OpenZeppelin의 Ownable 컨트랙트 무지성으로 external 지시자를 사용하면 외부에 허가받지 않은 사용자도 컨트랙트를 호출할 수 있다. 우리는 OpenZeppelin의 Ownable을 이용해 안전한 컨트랙르를 사용해야 한다. contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); functio..

    [CryptoZombie] 1-2 Zombies Attack Their Victims

    🧡 mapping Solidity에서 mapping은 파이썬의 dictionary와 비슷한 역할을 수행한다. key-value 구조를 갖고 있으며, 데이터를 저장하고 검색하는데 사용된다. mapping (address => uint) public accountBalance; mapping (uint => string) userIdToName; 🧡 Msg.sender msg.sender는 모든 함수에서 이용 가능한 전역변수다. 말 그대로 message sender를 뜻한다. mapping (address => uint) favoriteNumber; function setMyNumber(uint _myNumber) public { favoriteNumber[msg.sender] = _myNumber; } f..

    [CryptoZombie] 1-1 Making the Zombie Factory

    🧡 Solidity private 관례 Solidity에서는 private 지시자를 이용하여 함수를 선언할 때 함수명 앞에 _을 붙여주는 것이 관례라고 한다. uint[] numbers; function _addToArray(uint _number) private { numbers.push(_number); } 🧡 함수 제어자 Solidity에서는 view, pure 함수 제어자가 존재한다. view는 데이터를 읽기만 하고 변경하지 않을 때 사용하는 제어자이다. function sayHello() public view returns (string) { } pure는 데이터를 읽지도 않고 인자에 따라 반환값이 달라질 때 사용한다. function _multiply(uint a, uint b) private..

    [Chap4] 스마트 컨트랙트의 개념

    보호되어 있는 글입니다.