Skip to main content
Sui allows you to upgrade published packages while maintaining compatibility and security. This guide covers upgrade strategies and best practices.

Upgrade Basics

When you publish a package on Sui, you receive an UpgradeCap that allows you to publish new versions.

Publishing with Upgrade Capability

This creates:
  • Published package at address 0xPACKAGE_ID
  • UpgradeCap object sent to publisher

Upgrade Policies

Sui enforces three upgrade policies:
  1. Compatible: Most restrictive, safest
    • Can only add new functions and structs
    • Cannot modify existing public functions
    • Cannot change struct definitions
  2. Additive: Middle ground
    • Can add abilities to structs
    • Can change private function signatures
    • Can add new public functions
  3. Dependency-only: Least restrictive
    • Can make breaking changes
    • Only affects modules that depend on this package

Upgrading a Package

Step 1: Modify your code

Update your Move code with new features:

Step 2: Build the upgrade

Step 3: Authorize upgrade

Publish the new version:
The package will be published at a new address, but the original address remains as a reference.

Compatible Upgrades

Safe changes that don’t break existing code:

✅ Adding new functions

✅ Adding new structs

✅ Adding private functions

Incompatible Changes

Changes that break compatibility:

❌ Changing public function signatures

❌ Removing public functions

❌ Modifying struct definitions

Migration Strategies

Strategy 1: Additive Only

Add new functionality without changing existing code:

Strategy 2: Wrapper Pattern

Wrap old structs in new versions:

Strategy 3: Versioned Modules

Create separate modules for major versions:

Using Dynamic Fields for Upgrades

Add data to existing objects without changing struct:

Managing UpgradeCap

Check upgrade capability

Transfer upgrade rights

Make package immutable

Burn the UpgradeCap to prevent future upgrades:
Or via CLI:

Testing Upgrades

Test upgrade compatibility

Simulate upgrade locally

  1. Publish v1 on localnet
  2. Make changes
  3. Test upgrade
  4. Verify old objects still work
  5. Test new functionality

Best Practices

1. Plan for upgrades from the start

2. Document breaking changes

3. Provide migration paths

4. Use semantic versioning

5. Test thoroughly before upgrading

  • Test on devnet first
  • Verify all existing functionality works
  • Test new features
  • Check gas costs

Common Upgrade Patterns

Adding optional features

Deprecating old functions

Supporting multiple versions

Troubleshooting

Upgrade fails with compatibility error

Check what changed:
Revert breaking changes or use a less restrictive policy.

Lost UpgradeCap

If you lose the UpgradeCap, you cannot upgrade. Options:
  • Deploy as new package
  • Implement migration functions in v1

Old objects incompatible

Provide migration functions:

Next Steps