Immutable and Constant
What is a constant variable?
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract Constants {
address public constant myAddress = 0x777788889999AaAAbBbbCcccddDdeeeEfFFfCcCc;
uint public constant myUint = 143;
}What is an immutable variable?
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract Immutable {
address public immutable myAddress;
uint public immutable myUint;
constructor(uint _myUint) {
myAddress = msg.sender;
myUint = _myUint;
}
}Last updated