Member-only story
Not All Smart Contracts Are Immutable — Create Upgradable Smart Contracts
A dive into the world of Solidity
You may want to upgrade your smart contract for a number of reasons. You might want to fix a bug, add new features, or anything else. This article will teach you about the different things you need to know, conventional ways to do this, some of the philosophies that go into it, and more.
Introduction
When deploying your smart contracts on-chain, we all know that they are immutable.
But what if I told you… they are mutable?
Well, I wouldn’t really be correct. However, in a way, smart contracts “change” all the time. When people transfer tokens, when people stake in a contract, they have to update their balances to reflect this. The reason that they are immutable is that the logic in those contracts never changes and will be on-chain forever.
So, technically, they are and will always be immutable. Once deployed, that chunk of code can never be changed, and this is one of the major advantages of smart contracts.
However, this can be an issue if we want to:
1. Add new functionality to a protocol.
2. Fix a glaring bug in an existing protocol.
Now even though we can’t change the specific code deployed to a specific address, we actually can change a lot more than you think. And in this video, we are going to show you how to upgrade your smart contracts with hardhat and OpenZeppelin.
Also, I learned a lot of the material here from The State Of Smart Contract Upgrades by OpenZeppelin, Trail of Bits Blog, EIPs including the Diamon Standard, and a number of other helpful online resources.
Abstract
At first glance, you might think, “Doesn’t this defeat the narrative of smart contracts not being able to be changed?” And you’d be right. There are definitely some philosophical and…