Skip to main content

Use Dubhe to migrate a contract

Because there is always the possibility of bugs or new logic being added to a written contract, it becomes necessary to upgrade the contract. This section describes how to use Dubhe for versioning and upgrading contracts. Take the 101 contract as an example of a contract upgrade

Setting up a project

Start a Local Node

Check the current main code

Add version checking code

Execute the schemagen command
Determine if the version is up to date

Migrate a contract

Migrating contracts need to follow the basic guidelines of Sui Move upgrades, otherwise the upgrade will fail.
  1. Generate a new schema: value_v2, used to record the current number and the last number.
  2. Parameter number from 0-100 reduced to 0-10.
  3. Migrate value from the original value schema to the value_v2 schema.
Create a new schema
Execute the schemagen command
Modify the limitations of the number parameter, deprecate value in favor of value_2
Writing migration scripts, Please note that the migrated method must have a version number after migrate_to_, For example if you migrate from v1 to v2 then your migration method is migrate_to_v2, v2 to v3 is migrate_to_v3
  1. we change ON_CHAIN_VERSION from 1 to 2
  2. second step adds the migrate_to_v2 method
After modifying the contract, we upgrade.
So far the upgrade steps have been completed. OldPackageId is currently not working properly, newPackageId will work properly according to our newly added logic.