Skip to content
Build
Move on Aptos
Object Code Deployment

Object Code Deployment

This document goes through how you can deploy code to Objects. This is the recommended way to deploy code to the blockchain, as this reduces deployment complexity, and safely manages access control policies for the code owner.

Deploying code to objects will guarantee the following:

  • Each deployment publishes to a new address.
  • Only the owner of the code object can upgrade and freeze the code.

This means you can transfer the object to a new owner, and they will have full ownership of the code. You are granting them the rights to upgrade and freeze the code. There is no need to manage seeds, or deploy to a new address on each deployment. Object code deployment greatly simplifies the deployment process.

Instructions

Below are the instructions on how to compile, deploy and upgrade code to objects.

Compile code

Make sure <your_module_name> is left as a placeholder _. This is needed as the CLI command will override the address. Here is an example as <your_module_name> with the value my_module.

Move.toml
[addresses]
my_module = "_"

Compile your move code running the below command.

  • Replace <your_module_name> with the module name of your program.
  • Replace <your_address> with the address of your account.
Terminal
aptos move compile --named-addresses <your_module_name>=<your_address>

Deploy code to an object

Deploy the compiled code to an an object via the command:

  • Replace <your_module_name> with the module name of your code.
  • Replace <your_address> with the address of your account.
Terminal
aptos move create-object-and-publish-package --address-name <your_module_name> --named-addresses <your_module_name>=<your_address>

An example can be found below:

Terminal
aptos move create-object-and-publish-package --address-name my_module --named-addresses my_module=0xa0f0b100f243cbda3df93ceb42c0b9464c359a0853ed98f2bce558be9605e88b

This will ask if you want to publish the code under the specified object address.

Example output:

Terminal
Do you want to publish this package at object address 0x8d6eb306bcf6c61dbaa0dbf8daa8252e121b63e95991afcab3b12d3be7f001ab [yes/no] >

Congrats, you have deployed your code to a new object with a unique address!

3. Upgrade code in an existing package

If you wish to upgrade the code in the object deployed, run the following:

  • Replace <object_address> with the address of the object hosting the code.
  • Replace <your_module_name> with the address of your account.

Note: the module name should equal the object address, as the module is now deployed to that object address.

Terminal
aptos move upgrade-object-package --object-address <object_address> --named-addresses <your_module_name>=<object_address>

Example of the command above:

Terminal
aptos move upgrade-object-package --object-address 0x8d6eb306bcf6c61dbaa0dbf8daa8252e121b63e95991afcab3b12d3be7f001ab --named-addresses my_module=0x8d6eb306bcf6c61dbaa0dbf8daa8252e121b63e95991afcab3b12d3be7f001ab

This will ask if you want to upgrade the existing code deployed at the object address.

Example output:

Terminal
Do you want to upgrade the package 'MyPackage' at object address 0x8d6eb306bcf6c61dbaa0dbf8daa8252e121b63e95991afcab3b12d3be7f001ab [yes/no]

Congrats, you have upgraded your code in the existing object!