11

I deployed a smart contract to a substrate chain. How can I upgrade the smart contract's logic to a newer version?

Edit: I'm using ink! and deployed on Shibuya (Astar testnet)

2
  • What smart contract eDSL are you using? (Solidity, ink!, ..) On which parachain did you deploy?
    – P.Ossun
    Mar 7, 2022 at 16:44
  • ink! on Shibuya (Astar testnet) @P.Ossun
    – Minh Mốc
    Mar 8, 2022 at 2:03

2 Answers 2

13

You currently have two options for writing upgradeable smart contracts in ink!. For both of them we have example contracts. They differ in the following key characteristics.

The forward-calls example implements a classic forward-pattern:

  • The contract forwards any call that does not match a selector of itself to another contract. The address of this "another contract" can be changed by the instantiator of the contract (there is a notion of "admin" in the example contract).
  • The other contract needs to be deployed on-chain.
  • State is stored in the storage of the contract to which calls are forwarded.

The delegate-calls example on the other hand utilizes an API similar to Ethereum's delegatecall function:

  • The contract executes any call that does not match a selector of itself with the code of another contract. The address of this "another contract" can be changed by the instantiator of the contract (there is a notion of "admin" in the example contract).
  • The other contract does not need to be deployed on-chain.
  • State is stored in the storage of the originally called contract.

Future versions of OpenBrush (a library similar to OpenZeppelin, but for ink!) will contain support for the diamond pattern, another way of building upgradeable contracts.

3
  • Isn't pallet-contracts going to support set_code?
    – h4x3rotab
    Mar 25, 2022 at 17:36
  • @h4x3rotab Yes, that's correct, thanks for bringing that up! There's currently already a PR to include it in ink!. I'll update the above answer once it's merged.
    – cmichi
    Mar 28, 2022 at 3:05
  • 2
    FYI since you mentioned it, yesterday we released OpenBrush 1.6 with the diamond standard implementation
    – kriko.eth
    Apr 6, 2022 at 9:57
7

You can have a look at Parity upgradeable example: https://github.com/paritytech/ink/tree/master/examples/upgradeable-contracts (fixed broken link)

It follows proxy pattern of OpenZeppelin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.