Skip to content

How do you initialize a constructor when deploying a contract? #27

Answered by banool
banool asked this question in Questions
Discussion options

You must be logged in to vote

Note: Below you'll find the original answer suggesting that you use init_module. This still works, but these days we often caution against init_module due to some weird quirks with its behavior (for example, init_module only runs on publish, not upgrade, which confuses some folks). These days we recommend you add your own custom function, e.g. initialize, and then call it yourself manually after you publish. For example:

module addr::my_module {

    /// You are not the publisher of the package.
    const CALLER_NOT_PUBLISHER: u64 = 1;

    fun initialize(caller: &signer) {
        // Ensure only the module publisher can call this.
        assert!(signer::address_of(&caller) == @addr, error:

Replies: 1 comment

Comment options

banool
Mar 7, 2024
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by banool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
move Questions related to the Move Language
1 participant