How to choose and upgrade the Solidity version of your smart contract

In this guide, we are going to learn how to choose the Solidity version to use in your smart contracts and how to upgrade

In this guide, we are going to learn how to choose the Solidity version to use in your smart contracts and how to upgrade the Solidity version you're using.

The short answer is that you should always use the latest stable version because it's the most trusted version and it fixes all the security issues and bugs found in the previous versions and it gives you access to all the latest features.

At the time of writing this, the 0.8.9 is the most used across libraries, more recent code uses the 0.8.13 and 0.8.17 was released a few days ago.

Anything under 0.8.0 would be considered too old and should be upgraded. As a rule of thumb, bigger versions like 0.8.0 or before that the 0.7.0 should be used.

That's the ideal situation. But you're not always able to use the latest version.

If you use a library that has an older version of if the environment you're on uses an older version, you have to adapt your smart contract version.

For example, at the moment of writing this, Hardhat, Brownie and OpenZeppelin all support versions from 0.8.0 or above. So you can't really use a version below that and you cannot use versions too high above that.

But that's ok because they're using a very stable and trusted version. They are using the highest stable version.

Solidity uses a standard for versions like this: 0.x.y. You should always use the highest x versions and ideally the highest y but x is more important because if the y is too recent, it might introduce unknown bugs.

For example, if the latest version is 0.8.17, avoid using anything below 0.8.0 unless you can't do otherwise. Now, choosing between 0.8.13 or 0.8.17 is up to you. Either you trust the latest version or you trust most used version at the time which usually is the version that libraries like Hardhat use in their docs.

They are using the one that Solidity recommends here:

Solidity โ€” Solidity 0.8.18 documentation

And you can see the full list of versions here:

Releases ยท ethereum/solidity
Solidity, the Smart Contract Programming Language. Contribute to ethereum/solidity development by creating an account on GitHub.

To upgrade the Solidity version you'll need to:

  • Change the version at the top of your smart contract
  • Upgrade the code of the libraries so it uses the version you want
  • Get rid of all the old code that generates issues in the new version
  • Compile again to see if it works

And that's it ๐ŸŽ‰

Thank you for reading this article, if you want to get better at blockchain development, leave your email below and you'll get:

  • access to the private Discord of a community of Web3 builders
  • access to free guides that will teach you Blockchain Development