is there constructor function in move programming language?

116 Views Asked by At

Is there any kind of a constructor like function, which will run at the time of deployment in move programming language?

1

There are 1 best solutions below

1
On

You might be looking for init_module. This function runs just when you publish your module.

An example:

fun init_module(sender: &signer) {
    aptos_framework::managed_coin::initialize<MoonCoin>(
        sender,
        b"Moon Coin",
        b"MOON",
        6,
        false,
    );
}

From aptos-move/move-examples/moon_coin/sources/MoonCoin.move in aptos-core.

You can learn more about it here: https://aptos.dev/move/move-on-aptos/modules-on-aptos/.