Skip to content

Instantly share code, notes, and snippets.

@CJ42
Last active January 23, 2023 17:54
Show Gist options
  • Select an option

  • Save CJ42/0f7274ec0ce136afc3c355b03bd5e20d to your computer and use it in GitHub Desktop.

Select an option

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`
// 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