3

I would like to compile older versions of solc contract source code using a solc compiler on my local machine. Is there a website from which to download old solc compilers?

Google revealed a GitHub of old solcs, but I tried using node to run the .js. files without success (could be using this wrong).

Daniel Connelly
  • 383
  • 2
  • 9

2 Answers2

9

I maintain a Python library called py-solc-x that allows you to install and use multiple versions of solc at the same time. It supports versions >=0.4.11. I've included some code examples below to give an idea of how it works.

Installing a new version of solc:

>>> from solcx import install_solc
>>> install_solc('v0.4.25')

Checking installed versions and versions can be installed:

>>> from solcx import get_installed_solc_versions, get_available_solc_versions
>>> get_installed_solc_versions()
['v0.4.25', 'v0.5.3', 'v0.6.0']
>>> get_available_solc_versions()
['v0.6.0', 'v0.5.15', 'v0.5.14', 'v0.5.13', 'v0.5.12', 'v0.5.11', 'v0.5.10', 'v0.5.9', 'v0.5.8', 'v0.5.7', 'v0.5.6', 'v0.5.5', 'v0.5.4', 'v0.5.3', 'v0.5.2', 'v0.5.1', 'v0.5.0', 'v0.4.25', 'v0.4.24', 'v0.4.23', 'v0.4.22', 'v0.4.21', 'v0.4.20', 'v0.4.19', 'v0.4.18', 'v0.4.17', 'v0.4.16', 'v0.4.15', 'v0.4.14', 'v0.4.13', 'v0.4.12', 'v0.4.11']

Setting the current solc version using a pragma statement:

>>> set_solc_version_pragma('^0.4.20 || >0.5.5 <0.7.0', check_new=True)
Using solc version 0.5.8
Newer compatible solc version exists: 0.6.0
iamdefinitelyahuman
  • 2,876
  • 1
  • 12
  • 32
1

There are a couple of ways to do this and the Solidity documentation has a page on it:

Keep in mind you have the option to use the "cli binary" version (solc-bin) which is quite faster than the solcjs ( javascript implementation ).

In addition to all of these, if you use truffle, you can specify which version you would like to use with it in your truffle-config.js file.

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.5.10" // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {
      //   // See the solidity docs for advice about optimization and evmVersion
      //   optimizer: {
      //     enabled: true,
      //     runs: 200
      //   }
      //   //  evmVersion: "byzantium"
      // }
    }
  }

Micky Socaci
  • 1,312
  • 7
  • 15
  • Thank you so much! I will probably end up using Truffle, but visiting the https://github.com/ethereum/solidity/releases?after=v0.4.26 I found in the solidity documentation gave me the binaries I needed. – Daniel Connelly Dec 23 '19 at 20:41