Skip to content

Modules on Aptos

Aptos allows for permissionless publishing of modules within a package as well as upgrading those that have appropriate compatibility policy set.

A module contains several structs and functions, much like Rust.

During package publishing time, a few constraints are maintained:

  • Both Structs and public function signatures are published as immutable.
  • The init_module function plays a crucial role in module initialization:
    • When a module is published for the first time (i.e., the module does not exist on-chain), the VM will search for and execute the init_module(account: &signer) function.
    • When upgrading an existing module that is already on-chain, the init_module function will NOT be called.
    • The signer of the account that is publishing the module is passed into the init_module function.
    • This function must be private and not return any value.
    • The init_module function is commonly used to initialize module-specific data structures or set initial states.