eth.getCompilers() shows empty array

winksavillewinksaville Member Posts: 5
Following the instructions for Greeter and go-ethereum wiki for Contract-Tutorial both say to check if solc installed by doing:

> eth.getCompilers()
[]
>

But as you can see it returns an empty array where as it's expected to return:

> eth.getCompilers()
['Solidity']
>


But I had installed it via "npm install -g solc" as suggested here. But that seems to actually install "solcjs" not "solc" so that didn't work. What I finally did was build solidity from source following these instructions and then I added the resulting path to solc, which on my system is "$HOME/foss/solidity/build/solc/", to my $PATH and then things worked:

> eth.getCompilers()
["Solidity"]
> var greeterSource = 'contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }'
undefined
> greeterSource
"contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }"
> var greeterCompiled = web3.eth.compile.solidity(greeterSource)
undefined
>

(Note: the "undefined" lines you see above can be ignored according to the answer I got here)


So why did I have to install from sources, I would have expected the "npm install -g solc" to work?

Comments

  • VladWulfVladWulf Member Posts: 8
    The npm version is a javascript version of the compiler.
    I don't recommend using it because it is not complete and does not handle the error handling.
    That means that you can't check if the compilation was successful or a failure.

    You should use a standalone version with brew or with apt-get (or build it from source).
    Read the documentation here: https://solidity.readthedocs.io/en/develop/installing-solidity.html

    If the solc is not detected by geth use the argument --solc "path-to-solc" (you can get it with which solc on unix systems) when you use the geth keyword in your shell.
Sign In or Register to comment.