Skip to content
🎉 Welcome to the new Aptos Docs! Click here to submit feedback!
Build
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. Note that in this context, code refers to packages.

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. <your_module_name> value represents the owner of the code, or the owner of the object to deploy the code to. 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.
  • 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.
Terminal
aptos move deploy-object --address-name <your_module_name>

An example can be found below:

Terminal
aptos move deploy-object --address-name my_module

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!

Take note of the object address as you will need it later for upgrades.

Upgrade code in an existing package

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

  • Replace <your_module_name> with the existing module name.
  • Replace <code_object_addr> with the address of the object hosting the code.

Note: the value for the account name should now be the object address, as the package containing the module(s) is now deployed to that address.

Terminal
aptos move upgrade-object --address-name <your_module_name> --object-address <code_object_addr>

Example of the command above:

Terminal
aptos move upgrade-object --address-name my_module --object-address 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!