Programming Language/Solidity
Solidity - Immutable
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;
}
}