Are smart contracts really immutable? Learn about Upgradeable Smart Contract.

The immutability of smart contracts might not be the immutability that you think. Image source

The need of updating the smart contracts

If the smart contracts are all unchangeable, what to do if you spot a bug in the contracts? How to add the new features into the contracts iteratively? What if you just have to update the logic as the requirement changed?

1. Migrate to a new smart contract manually

The traditional contract between two parties can be changed when both of the parties agreed to do so. In blockchain, it is common to tell the community that you deployed a new smart contract and try to convince every user to adopt the new contract. The user may need to manually withdraw the fund from the original smart contract and interact with the new version of the smart contract.

2. Upgrade using proxy pattern

Isn’t it great if we can replace the logic without changing the smart contract address that users interact with? This is where proxy pattern comes in handy.

How to preserve state between different versions

When proxy forwards the transaction to the implementation contract using delegatecall opcode, it executes the implementation contract’s code in the context of the proxy’s state. The states are preserved when replacing the logic contract because the states are always in the proxy.

How to use it

You can write the proxy contract by yourself or use the OpenZeppelin Upgrades Plugins. The guide is clear and simple so I won’t dive deep into the hands-on tutorial.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abby Low

Abby Low

Software engineer, dreamer, another cat lover. Just share what I’ve learned.