5

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

2 Answers 2

3

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).

4
  • I added step by step instructions - better?
    – nergall
    Commented Jan 4, 2017 at 12:56
  • Hi nergall, It all worked perfectly. Thank you for the detailed instructions! I don't yet understand everything you just showed me but you have certainly made my world bigger. I will study this for a few days and then I should have some thoughtful questions to ask. After that I hope to write a tutorial of my own so that I can solidify my new knowledge and share it with others. Thank you again for your help, John Commented Jan 5, 2017 at 12:36
  • Great, glad to help!
    – nergall
    Commented Jan 5, 2017 at 13:22
  • When running this : I get error like "no such file or directory, open 'C:\Users\...\SmartContracts\Examples\Multiply\Solidity\contracts\build\:MultiplyContract.abi' It seems that a : is added in front of the contract name? Commented Dec 6, 2017 at 15:06
1

The question is already marked answered but I will add few details for completeness.

1.You can download the solidity executable from their github page https://github.com/ethereum/solidity/releases

  1. Add the executable to your classpath.

  2. Make sure that you have Visual studio installed (i suggest 2015 ).

  3. Once you have added the executable to classpath, open a CLI and type solc --version. This should give you the solidity compiler version installed.

  4. Now start geth. You don't need to enable admin module. As admin.setSolc('') is not required.
  5. You don't even need to add --solc paramater to your 'geth start' command. Geth will pick it up from your system path.
  6. Once get is started check your compiler. eth.getCompilers() ["Solidity"]

Alternatively you can use solc Npm package(IMHO second best). OR, you can build Solidity from Source if you wanna be a contributor. This requires Cmake, git and Visual Studio.

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.