Windows Solc Installation – How to Install Solc Compiler on Windows 8

installationsolcwindows

I need a command line compiler in order to make an expert system that automatically builds, tests, and deploys systems of smart contracts based only on metadata. I have tried for several days to install solc without success. I will admit that I only have average intelligence but I thought the point of Ethereum was to empower regular people. It shouldn't be this complicated unless the point of the complexity is to limit the amount of people who can solve the puzzle in a given amount of time. It feels like I am doing a proof of work.

Everything I have tried so far (NPM) is documented but before I post everything here I want to know if there are alternative compilers that can be used in an automated process or if there is another way to install solc or perhaps build it from source. If building from source is an option I will need a tutorial because I have no experience with C++. I do have Visual Studio installed on my machine if that will help.

Very briefly I have tried installing from NPM both locally and globally and I have tried geth --solc path and admin.setSolc('path'). In any case, I don't think defining the path is my problem because after NPM installs there is no solc.exe installed anywhere on my computer that I can find – only a solc directory populated with solcjs files.

Any ideas would be greatly appreciated
Thanks, John

As a side note I had a lot of difficulty making a local blockchain and I had difficulty finding learning resources. To that end I made a tutorial found here on GitHub which should get another noob like me up and running in short order. One can cut and paste code from the tutorial to start a local block chain and the most helpful resources are indexed. I will continue to work on the index to make it more clear and to add new resources as they are found. If I can find out how to install solc I will write something similar so that the next person coming along can have an easier time.

Thanks again, John

Hi All, it's a day later now and I have some of this problem solved.

Neither the command npm install solc nor npm install -g solc actually installs solc. Those commands install JavaScript bindings for solc.

Check out the The NPM page for solc. It is very misleading- it says solc in big letters at the top. But right below are two links where I think solc and be found.

The links are reproduced here and here.

The problem is that I don't know how to install solc from either of those two GitHub pages and so I didn't even recognize them as places where solc could be acquired. I still don't know what to do with those pages.

Not to worry, after googling for a few hours more I found the this page with a big picture entitled Village Idiot. I hope this is some kind of inside joke and not and insult to average people like myself looking for help. Anyway, on this page is a release of of an executable that installs solc along with the Mix IDE, AlethZero, geth and eth.

Now if I start Geth with the following option --solc "C:\Program Files\cpp-ethereum\solc", I can then type eth.getCompilers() into the console and I will see [solidity] as the result returned.

In the alternative I can start geth without the solc option and later type the following command into the JavaScript console when I want to use the compiler.
admin.setSolc('C:\\\Program Files\\\cpp-ethereum\\\solc')
Notice that the JavaScript console requires that three slashes be used where there would normally be only one. I read on Stack Exchange that this is because the slash is an escape character in JavaScript. Also note that a single or double quotes are required around the path in this case because there is a space in the path between the words "Program" and "Files".

I haven't actually tried to compile anything yet. I will report back if there is trouble.

In the mean time I would be grateful if someone would tell me how to install solc from the following pages here and here. I need to know because the version on the Village Idiot page is from June and I don't think the page is supported anymore.

Thanks again, John

Best Answer

One relatively easy solution is to install node.js and use the solc npm package. I used it myself when I initially started playing with ethereum contracts and it was a snap to set up.

Here are the steps -

  • install the latest version of node.js
  • create a folder for the project
  • add solc package to your package.json file, or use the following package file -

    { "name": "eth_compiler", "version": "0.0.1", "engines": { "node": ">=7.0.0", "npm": "^3.0.0" }, "dependencies": { "solc": "^0.4.7" } }

  • run npm install in the folder

  • add a small js script to the folder (compile.js) - it will receive the contract file name and output the abi/code files you need.

Here's a example -

var solc = require('solc');
var fs = require('fs');

var inputFilePath = process.argv[2];
var outputPath = process.argv[3];

// note - using the synchronous version of the file system functions for simplicity and because the async version isn't really needed in this case
var contractSolidity = fs.readFileSync(inputFilePath , 'utf-8');
if (!contractSolidity)
    return console.error('unable to read file: ' + inputFilePath );

var output = solc.compile(contractSolidity, 1);
for (var contractName in output.contracts) {
    var abi = output.contracts[contractName].interface;
    var code = output.contracts[contractName].bytecode;
    fs.writeFileSync(outputPath + '/' + contractName + '.abi', abi, 'utf-8');
    fs.writeFileSync(outputPath + '/' + contractName + '.code', code, 'utf-8');
}
  • once you have that file, you can simply execute the following command in the new folder - node compile [inputFilePath] [outputPath]

and it should generate the compiled files.

Note: I did test it locally and managed to compile a contract so I believe it should work but it's worth mentioning that I have both party & cpp-ethereum installed on my machine (parity wasn't running at the time of this script's execution).