A Solidity Version Manager using Sokt

Joshua
Web3 Labs
Published in
3 min readApr 7, 2020

The Problem

In my last blog post, I discussed various issues surrounding the requirement to use multiple versions of the Solidity compiler on a day-to-day basis here at Web3 Labs, and how we’ve gone about writing software to streamline the experience of doing so. Web3j now uses the Sokt library to compile Solidity code, meaning that almost all possible Solidity versions can be targeted without user intervention.

Whilst Sokt allows for efficient compilation of smart contracts programmatically, it doesn’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; essentially it allows you to easily switch between different versions of Solidity from the command line, and to download & install new versions, all without leaving your Terminal. The easiest way to communicate how exactly this works is with a video:

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

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.

This post first appeared on the Web3 Labs blog at https://blog.web3labs.com/a-solidity-version-manager-using-sokt

--

--