2020.코딩일지

[solidity] DataType/function/ (feat.솔리디티깨부수기) 본문

Block Chain

[solidity] DataType/function/ (feat.솔리디티깨부수기)

개발하는라푼젤 2022. 11. 28. 18:42
728x90

1. 데이터타입

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract lec1 {
    bool public b = false;

    bool public b1 = !false; //true
    bool public b2 = false || true; //true
    bool public b3 = false == true; //false
    bool public b4 = false && true; //false

    bytes4 public bt = 0x12345678;
    bytes public bt2 = "STRING"; //0x535452494e47

    address public addr = 0xf8e81D47203A594245E36C48e151709F0C19fBe8;

    int8 public it = 4;
    uint256 public uit = 131234;
    uint8 public uit2 = 255; // 266넣으면 에러남(255까지가능)
}

 

2. 함수

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract lec2{
    uint public a = 3;

    //1. parameter와 return값이 없는 함수정의
    function changeA1() public{
        a = 5;
    }

    //2. parameter는 있고 return값이 없는 함수정의
    function changeA2(uint256 _value) public {
        a = _value;
    }

    //3. parameter도 있고 return값이 있는 함수정의
    function changeA3(uint256 _value) public returns(uint256){
        a = _value;
        return a;
    }
}
Comments