Skip to content

Constructors #306

Description

@ItsNickBarry

Constructors are not used because they are generally not compatible with upgradeable contracts. However, some contracts require initialization, so users must write their own constructors.

We could include overridable _constructor functions in each contract. Possibly unimplemented, to force the user to override and make some decisions specific to the contract (and encourage setting immutable variables to replace certain storage accessors).

// _Ownable.sol
constructor () {
    _Ownable();
}

function _Ownable () internal virtual;

Or we could offer a library of composable initializers for users to import and call depending on which contracts they're using.

// Solidstate library
library Constructor {
    function Ownable () {
        _setOwner(msg.sender);
    }
}

// user's contract
constructor () {
    Constructor.Ownable();
}

The former approach will cause problems with hardhat-exposed. The latter is error-prone, both on the user's end and in cases of API changes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions