Skip to main content
Upgrade an existing program that has already been deployed to the Aleo network. This command creates upgrade transactions for programs with constructors, allowing you to modify program logic while maintaining state.

Usage

Options

Fee Options

number
Priority fee in microcredits. Higher fees may result in faster confirmation.
string
Record to use for paying the priority fee

Transaction Actions

boolean
Broadcast the upgrade transaction to the network
string
Save the upgrade transaction to the specified directory
boolean
Print the upgrade transaction in JSON format

Environment Options

string
default:"testnet"
Network to deploy to (mainnet, testnet, canary)
string
Custom API endpoint URL
string
Private key for signing (can also use PRIVATE_KEY environment variable)

Build Options

string[]
Skip upgrade of programs containing these substrings
boolean
Skip deployment certificate generation (advanced usage)
boolean
Skip confirmation prompts

Examples

Basic upgrade

Upgrade with priority fee

Save upgrade transaction without broadcasting

Skip specific programs

Upgrade to mainnet

Upgrade Requirements

Constructor Required: Only programs with a constructor (marked with @noupgrade or regular constructor) can be upgraded. Programs without constructors can only be upgraded once using special migration rules.

Valid Upgrade Rules

  1. Constructor Must Exist: New version must have a constructor
  2. Mappings Cannot Change: Mapping definitions must remain identical
  3. Records Can Be Added: New record types can be added
  4. Function Signatures: Can modify logic but some constraints apply
  5. Edition Increments: Edition number automatically increments

Example Valid Constructor

Upgrade Process

1

Build updated program

Leo automatically builds your project before upgrading.
2

Verify program exists on network

The command checks that the program is already deployed.
3

Validate upgrade compatibility

Checks that the upgrade follows all rules:
  • Constructor requirements
  • Mapping compatibility
  • Naming structure
  • Consensus version compatibility
4

Generate upgrade transaction

Creates the upgrade deployment transaction with incremented edition.
5

Broadcast or save

Either broadcasts to network or saves to file.

Upgrade Validation

Before upgrading, the command validates:

Program Existence

Upgrade Compatibility

Warnings

Edition System

Each upgrade increments the program’s edition number:
The edition tracks the program version and is used for:
  • Key generation
  • Transaction validation
  • State migration

Cost Estimation

The command displays estimated costs before broadcasting:

JSON Output

Enable --json-output for machine-readable results:

Consensus Versions

Different consensus versions have different upgrade rules:
  • V7+: Program naming structure validation
  • V8+: One-time upgrades for programs without constructors
  • V9+: Constructor required for all upgrades

Common Issues

Program not found on network

Invalid upgrade: mapping changed

Mapping definitions cannot be modified:

Constructor missing

Add a constructor to your program:
  • Deploy - Initial program deployment
  • Build - Compile programs
  • Execute - Execute program functions

Best Practices

Test upgrades on testnet first: Always verify upgrade compatibility on testnet before upgrading mainnet programs.
Use version control: Tag each upgrade in git to track program evolution.
State preservation: Upgrades preserve all on-chain state including mapping values and program balance.

Troubleshooting

Upgrade transaction fails

Check the error message for specific validation failures:

Fee estimation errors

Ensure you have sufficient balance:

Consensus version mismatch

Update the consensus heights if needed: