Using Solang on the command line

The Solang compiler is run on the command line. The solidity source file names are provided as command line arguments; the output is an optimized wasm or bpf file which is ready for deployment on a chain, and an abi file.

The following targets are supported right now: Parity Substrate, Solana Ethereum ewasm, and Sawtooth Sabre.




This means that the command line is solang followed by any options described below, followed by one or more solidity source filenames.


-v, --verbose
Make the output more verbose. The compiler tell you what contracts have been found in the source, and what files are generated. Without this option Solang will be silent if there are no errors or warnings.
--target target
This takes one argument, which can either be ewasm, sabre, solana, or substrate. The default is substrate.
Generate documentation for the given Solidity files as a single html page. This uses the doccomment tags. The result is saved in soldoc.html. See Tags for further information.
-o, --output directory
This option takes one argument, which is the directory where output should be saved. The default is the current directory.
-O optimization level
This takes one argument, which can either be none, less, default, or aggressive. These correspond to llvm optimization levels.
--importpath directory
When resolving import directives, search this directory. By default import will only search the current directory. This option can be specified multiple times and the directories will be searched in the order specified.
--help, -h
This displays a short description of all the options

This option causes Solang to emulate the behaviour of Solidity standard json output. No output files are written, all the output will be in json on stdout.

This feature is used by Hyperledger Burrow’s deploy tool.

--emit phase

This option is can be used for debugging Solang itself. This is used to output early phases of compilation.


Output Abstract Syntax Tree, the parsed and resolved input
Output control flow graph.
Output llvm IR as text.
Output llvm bitcode as binary file.
Output assembly text file.
Output wasm object file; this is the contract before final linking.
Disable the Constant Folding Pass codegen optimization
Disable the Strength Reduction Pass codegen optimization
Disable the Dead Storage pass optimization
Disable the Vector to Slice Pass optimization

Running Solang from docker image

First pull the last Solang image from docker hub:

docker pull hyperledgerlabs/solang

And if you are using podman:

podman image pull hyperlederlabs/solang

Now you can run Solang like so:

docker run --rm -it hyperledgerlabs/solang --version

Or podman:

podman container run --rm -it hyperledgerlabs/solang --version

If you want to compile some solidity files, the source file needs to be available inside the container. You can do this via the -v command line. In this example /local/path should be replaced with the absolute path to your solidity files:

docker run --rm -it -v /local/path:/sources hyperledgerlabs/solang -o /sources /sources/flipper.sol

On podman you might need to add :Z to your volume argument if SELinux is used, like on Fedora. Also, podman allows relative paths:

podman container run --rm -it -v .:/sources:Z hyperledgerlabs/solang -o /sources /sources/flipper.sol

On Windows, you need to specify absolute paths:

docker run --rm -it -v C:\Users\User:/sources hyperledgerlabs/solang -o /sources /sources/flipper.sol