py-solc 1.2.0 — Now with easy installation of different versions of the solc compiler.

One of the first pieces of code that I wrote was a wrapper around the solc command line compiler for Solidity. Those scripts were originally part of the Populus code but were eventually extracted to create the py-solc library.

py-solc exposes some high level functions for performing compilation of solidity source files.

>>> from solc import compile_source
>>> compile_source("pragma solidity ^0.4.0;\n contract Foo {}", output_values=["bin", 'abi'])
{'<stdin>:Foo': {'abi': [],
'bin': '60606040523415600b57fe5b5b60338060196000396000f30060606040525bfe00a165627a7a723058201af5097131eecd7d69436b13c562763c387b13c4fb1ed58951f580d2bf81e06a0029'}}

While this functionality has been helpful, one of the ongoing pain points has been access to historical versions of solidity. An important step in contract verification is confirming that the contract bytecode does indeed match the compiler output from the version of solidity it was installed with. The solcjs package for node has the ability to pull and use older versions of solidity making this relatively easy in Javascript. This functionality is however not present in the solc command line compiler, and installing older versions is not trivial.

I’ve used some crude bash scripts to handle installing older versions of the solc compiler in my CI environments for quite a while. While they have served their function well, they are not very extensible or usable for other purposes.

In the most recent release of py-solc I’ve refactored these bash scripts to introduce a new experimental feature. The ability to install different versions of solc either from python or your command line using py-solc.

>>> from solc import install_solc
>>> install_solc('v0.4.12')

or, from your command line

$ python -m solc.install v0.4.12

This functionality is currently only available for the following solidity versions and corresponding operating systems.

  • v0.4.1 — linux
  • v0.4.2 — linux
  • v0.4.6 — linux
  • v0.4.7 — linux
  • v0.4.8 — linux/osx
  • v0.4.9 — linux
  • v0.4.11 — linux/osx
  • v0.4.12 — linux/osx

So, if you need a specific version of solc either for your local environment or for some automation/testing, I’d recommend giving this feature a spin. You should also feel free to open up an issue if you need a version of solidity that’s not in this list, or even better, open up a pull request adding support for it.

Like what you read? Give Piper Merriam a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.