Upgrading Contracts

Rubidity, unlike Solidity, has native support for upgrading contracts. All you need to do is declare the contract upgradeable when you define it:

contract :UpgradeableToken, upgradeable: true do

All contracts marked upgradeable can upgrade their own implementations at any time using the upgradeImplementation function that exists on contract variables, such as this:

this.upgradeImplementation(newInitCodeHash, newSourceCode)

You must provide the init code hash and source code of the desired new implementation, which must be a supported contract. However as with EOA deploys, you don't have to provide the source code as long as the implementation has been deployed before.

Conceptually these upgrades mirror how a Solidity contract would behave if it had the typical ERC-1967 proxy setup. Calling this.upgradeImplementation is akin to the 1967 contract calling proxy.upgradeImplementation.

As in the proxy case, the new implementation will be active for all future calls and the old implementation will be active for the remainder of the call in which the upgrade happened.

This means if you want to do a migration with the new implementation you must do an external call to yourself.

Last updated