Our Blog

Full-stack development and intelligence for blockchains

A Solidity Version Manager using Sokt

The Problem

In my last blog post, I discussed the issues presented by having to switch between different versions of the Solidity compiler on a daily basis. Sokt, is the software written by Web3 Labs to tackle these problems and to streamline the experience for developers. The great news is that Web3j now uses the Sokt library to compile Solidity code. This means that almost all possible Solidity versions can be targeted without user intervention! 

But, whilst Sokt allows for efficient compilation of smart contracts programmatically, it didn't entirely solve the problem that we were facing when working with multiple projects all requiring different Solidity versions, often directly from the command line. For that, we designed a CLI-based tool called svm (Solidity Version Manager), which leverages the Sokt library to install and manage Solidity versions from the CLI. 

The Solution

If you’ve used Jabba for managing Java versions or nvm for managing node.js versions before, this kind of tool will be familiar to you. It allows you to easily switch between different versions of Solidity from the command line and to download and install new versions, all without leaving your Terminal.

The easiest way to communicate how exactly this works is with a video:

Installing the Solidity Version Manager

The video above demonstrates the process of

1. Installing svm
2. Using it to list available Solidity versions to install from a remote listing
3. Installing & using Solidity 0.5.9
4. installing & using 0.6.2

All this from the same shell!

The creation of aliases is also supported. For example, one might want to alias ‘latest’ to 0.6.3, or ‘default’ to 0.5.9, if 0.5.9 was the most frequently used version on a certain system. When installing Solidity with svm on Windows or Linux, the latest binaries are downloaded directly from the Solidity releases page on Github. However, the native images for macOS are not distributed on this page so Web3 Labs has produced and hosted statically linked builds for macOS.

Other supported commands using svm are as follows:

 

install <version>  Download and install Solidity
uninstall <version> Uninstall Solidity
use <version> Modify PATH to use specific Solidity version
current Display currently 'use'ed version
ls  List installed versions
ls-remote List remote versions available for install
alias <name> <version> Resolve or update an alias
unalias <name> Delete an alias
deactivate Deactivates svm in the current shell

You might think that since Sokt targets the JVM, there will be a Java dependency. But by using GraalVM, svm is available as a native image for both Linux and macOS. However, a Java 8 dependency remains on Windows, as GraalVM has not matured on Windows enough to produce executables for complex projects on Windows.

Installation

We hope that Sokt and svm will address a significant pain point for lots of Solidity developers; if you’d like to give svm a try, it can be installed like so on Linux and macOS:

curl -L https://github.com/web3j/svm/raw/master/install.sh | bash && source ~/.svm/svm.sh

And with Windows:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Invoke-Expression (

  Invoke-WebRequest https://github.com/web3j/svm/raw/master/install.ps1 -UseBasicParsing

).Content

It’s really great for developers to be able to save time on repetitive and monotonous tasks like managing compiler versions. If svm is useful to you, you might very well also benefit from using Sokt to integrate similar capabilities into your deployed software, as well as other open source software from Web3 Labs.