상세 컨텐츠

본문 제목

Solidity - Immutable

Programming Language/Solidity

by Yongari 2022. 12. 21. 21:45

본문

 

Immutable variables are like constants. Values of immutable variables can be set inside the constructor but cannot be modified afterwards.

불변 변수는 상수와 같습니다. 불변 변수의 값은 생성자 내부에서 설정할 수 있지만 이후에는 수정할 수 없습니다.
 
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract Immutable {
    // coding convention to uppercase constant variables
    // 상수변수의 코딩 컨벤션은 대문자다.
    
    address public immutable MY_ADDRESS;
    uint public immutable MY_UINT;

    constructor(uint _myUint) {
        MY_ADDRESS = msg.sender;
        MY_UINT = _myUint;
    }
}
 
 

 

 

Remix Link

'Programming Language > Solidity' 카테고리의 다른 글

Solidity - Ether and Wei  (0) 2022.12.22
Solidity - Reading and Writing to a State Variable  (0) 2022.12.21
Solidity - Constants  (0) 2022.12.21
Solidity - Variables  (0) 2022.12.21
Solidity - Primitive Data Types  (0) 2022.12.19

관련글 더보기