lein-solc solidity compiler with watch mode

Intro

If you are a developer working in the blockchain space, chances are you have to work with smart contracts.

I just released a Leiningen plugin for compiling smart contracts written in the Solidity language, that facilitates compiling smart contracts code as part of the build process - helpful during deployment or CI. To aid in development the plugin also includes an auto option, that will watch and recompiles on source code changes.

Source code is published on GitHub, plugin is availiable via clojars.

Using the plugin

Start by adding the plugin to your project.cljs:

:plugins [[lein-solc "1.0.0"]]

add the map with the options:

:solc {:src-path "resources/contracts/src"
       :build-path "resources/contracts/build"
       :solc-err-only false
       :contracts ["Test.sol" "lib/string.sol"]}

In plain english:

  • This assumes there are two contracts Test.sol and string.sol, former in the directory "resources/contracts/src", latter in the "lib" sub-directory (both relative to the projects root directory).
  • The compiled binaries and ABI will end up in the "resources/contracts/build".
  • :solc-err-only set to false means both errors and warnings will be reported to your standard output (set to true to see only the compilation errors ).

    Now you can call lein solc to compile the contracts or lein solc auto to watch the sources and recompile them on changes.

    For other options check out the plugin’s documentation.
Written on May 1, 2018