You can easily install solc-js from npm official package repository:

# npm install -g solc

It will install solc-js under /usr/local/bin/solcjs -> ../lib/node_modules/solc/solc.js

Basic syntax to compile a smart contract written in Solidity:

$ solcjs --bin contract.sol

If you use external contracts, imports or OpenZeppelin:

$ solcjs --bin --include-path node_modules/ --base-path . MainContract.sol

If you want to have a look to other parameters, here they are:

$ solcjs --help 
Usage: solcjs [options]

  -V, --version                        output the version number
  --version                            Show version and exit.
  --optimize                           Enable bytecode optimizer. (default: false)
  --optimize-runs <optimize-runs>      The number of runs specifies roughly how often each opcode of the deployed code will be executed across the lifetime of the contract. Lower values
                                       will optimize more for initial deployment cost, higher values will optimize more for high-frequency usage.
  --bin                                Binary of the contracts in hex.
  --abi                                ABI of the contracts.
  --standard-json                      Turn on Standard JSON Input / Output mode.
  --base-path <path>                   Root of the project source tree. The import callback will attempt to interpret all import paths as relative to this directory.
  --include-path <path...>             Extra source directories available to the import callback. When using a package manager to install libraries, use this option to specify directories
                                       where packages are installed. Can be used multiple times to provide multiple locations.
  -o, --output-dir <output-directory>  Output directory for the contracts.
  -p, --pretty-json                    Pretty-print all JSON output. (default: false)
  -v, --verbose                        More detailed console output. (default: false)
  -h, --help                           display help for command

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply