I want to find a simple way to compile a single sol file on local, without using truffle, remix etc. Something i'd do for js file like running node example.js in command line.

I installed solc using npm install -g solc. Then I tried to compile my file with solc --bin sourceFile.sol. However, it returns "command not found: solc".

solcjs --version

returns "0.8.9+commit.e5eed63a.Emscripten.clang"

solc --version

return command not found: solc


  1. How do I check solc version I just installed?
  2. I don't want to wrap my sol file in a javascript file and run node index.js. Is there a more direct command that simply run the sol file without working around it, maybe like solc ..... example.sol?

Additionally, i also tried

solcjs --bin example.sol

it got me the following. why is that?

Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: " to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information. --> example.sol

4 Answers 4


The version of Solc node installs is as you found out, solcjs. This is the command you would use to compile your contract (as you attempted).

Where things have gone wrong is the missing SPDX entry that is now required at the top of all smart contracts since Solidity 0.6.8

This should be a simple fix by simply adding the SPDX line to the beginning of your contract before the pragma as follows:

// SPDX-License-Identifier: UNLICENSED

Once you make this change to your smart contract it should compile barring any further issues. You do not need to compile with truffle it just as others have suggested makes the development process a bit more streamlined and provides migration and testing features.

For more information regarding the SPDX please see the information here, SPDX License Identifier


Check Truffle. With it your compilation will be 100x easier.

First install truffle via npm - npm install -g truffle

Then choose directory where your project will be and create new truffle project via truffle init comand

Then create new contract with command truffle create contrac MyContractName - It will create .solc file int /contracts directory

And when you are done implementing the contract you have to run truffle compile to compile the contract

If you want different version of solc enter the truffle.config file created by the init command, find the solc: key in the JSON and set it to the desired version.

In my opinion this is the easiest way to develop contracts. You cant dig around their documentation for what migrations are and how to write unit tests of your contracts.

Have fun!

  • Yes Truffle does in a few steps what I had to do writing scripts. But the ABI and bytecode came out in formats that didn't match my deploy script and while it seemed simple to get them to work (hex? JS object? How complicated could it be?) I found myself going in circles again. But I intend to learn it and use it, either Truffle or Hardhat, which a few people tell me is less work. I'm new to blockchain and contracts but not to crypto, I have 17 years in it and everything else was a lot more complicated than contracts. Solidity is easy. So it was odd to be stymied by such simple stuff.
    – Chris Fox
    Jan 5, 2022 at 13:16
  • I have switched to Hardhat :D, it is better in my opinion. Much more robust in regards to big projects. Jan 5, 2022 at 17:09

you can use the solc-select tool to install all versions of Solidity compiler



Solc has a second parameter that formerly was an integer, the number of contracts you intend it to compile. Now the second parameter is a callback for processing imported files, good luck doing that on the command line.

Almost everything I studied learning smart contracts was a critical year or two old and it took me three days of frustration to get my stuff to compile; Truffle worked but the output wouldn't work in my deploy scripts. I ended up command-line compiling with solcjs and even then tweaking the output to deploy.

And even one of the path parameters on solcjs didn't work. I had to copy my contract up into the same folder

  • "good luck doing that on the command line" - solcjs does provide a callback so it should work just fine. If you need to use it on the CLI I'd recommend just getting a static binary from solc-bin though. The script is very bare-bones and missing a lot of options.
    – cameel
    Jan 4, 2022 at 5:29
  • "And even one of the path parameters on solcjs didn't work." - was this because the contract was importing something from npm packages? The recently added --include-path option is helpful with that but in older versions of solc you can also use remappings. solcjs does not support remappings but even in that case you can work around it by creating symbolic links (e.g. @openzeppelin -> node_modules/@openzeppelin.
    – cameel
    Jan 4, 2022 at 5:33
  • No, the import path worked fine, it was the primary one, the path to the contract, that didn't work. Yes I too find this very hard to believe but I spent a lot of time on it and finally had to copy the contract to the same directory and use the dot current directory alias as the contract path. That worked immediately. I miss the good ol' days where using the most current release of a package or framework was the only sane way to operate. Twenty years ago we mocked Java for issuing updates just about every day, and distrusted it for that reason.
    – Chris Fox
    Jan 5, 2022 at 12:06
  • If you can still reproduce it, please report it in solc-js. I spent a lot of time recently squashing various path-related bugs but these were mostly in the native solc and should not be happening in solc-js (which is interfacing with an emscripten binary completely stripped of the CLI interface and has to be used via a script like solcjs that provides provides a callback). If it's really a bug I'd like to get it fixed.
    – cameel
    Jan 5, 2022 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.