Last active
January 23, 2023 17:54
-
-
Save CJ42/0f7274ec0ce136afc3c355b03bd5e20d to your computer and use it in GitHub Desktop.
Example to show how `contract` type can be used when defining `constant` or `immutable`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: GPL-3.0 | |
| pragma solidity ^0.8.0; | |
| contract ContractTemplate { | |
| // some logic here... | |
| } | |
| abstract contract MyContract { | |
| // This will not compile and throw the error | |
| // TypeError: Initial value for constant variable has to be compile-time constant. | |
| ContractTemplate constant a = new ContractTemplate(); | |
| ContractTemplate immutable b = new ContractTemplate(); | |
| ContractTemplate immutable c; | |
| constructor() { | |
| c = new ContractTemplate(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment