ethereum / go-ethereum

Go implementation of the Ethereum protocol
https://geth.ethereum.org
GNU Lesser General Public License v3.0
47.6k stars 20.16k forks source link

eth_compilers, eth_compileSolidity are gone in go-ethereum 1.6.0 #3793

Closed beatrizsanchez closed 6 years ago

beatrizsanchez commented 7 years ago

System information

Geth version: v1.6.0-unstable-6d038e76/linux/go1.7.3 OS & Version: Linux/Ubuntu 16.04.1 LTS (x86_64) Commit hash : 6d038e76

Expected behaviour

Running eth.getCompilers() in the geth console should return an array of compilers ['solidity'] that could even be empty ( [] )

Actual behaviour

The command returns Error: The method eth_getCompilers does not exist/is not available but I have started the node with --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" and I am able to run other eth commands. I was actually trying to execute the command via RPC with web3j and was getting an error then realized it didn't work in the console either.

> eth.compile
{
  lll: function(),
  serpent: function(),
  solidity: function()
}

Steps to reproduce the behaviour

  1. Attach the console to a running node with -ipc enabled
  2. Run eth.getCompilers()
  3. If no compilers are installed you should get [], not an error message
fjl commented 7 years ago

Compiling via RPC has been removed in #3740 (see https://github.com/ethereum/EIPs/issues/209 for why). We will bring it back under a different method name if there is sufficient user demand. You're the second person to complain about it within 2 days, so it looks like there is demand.

fjl commented 7 years ago

Leaving this open so other people can find this issue and raise their voice here.

beatrizsanchez commented 7 years ago

@fjl, Thanks for the info. It would be convenient to have it on RPC but I have the issue as well on IPC, any idea why?

fjl commented 7 years ago

When I say RPC I mean the IPC endpoint too. The methods have been removed by the linked PR. There is no way to invoke solc through geth at this time.

ghost commented 7 years ago

This feature is really useful. Can we please have the compilers available?

mavstronaut commented 7 years ago

Eth.compile is a great feature!

islandBilly commented 7 years ago

I too think eth.compile is a great feature, and it was an important part of my Dapp, so that people could generate a simple contract from a web form, compile and deploy it, all without knowledge of Solididty or the need to use Mist.

kunalbansal92 commented 7 years ago

Updated my project due to this issue https://github.com/ethereum/solidity/issues/1708, And now :/

vyorkin commented 7 years ago

Also voting for bringing it back, otherwise at least we should update the official docs and tutorials to not confuse a newcomers (like me)

RomanKrakowiak commented 7 years ago

Living exactly the same situation as the comment above from vyorkin. Newcomer, confused by outdated official tutorial. also, please update the private network genesis block specifications in the official documentation please :p

michiels commented 7 years ago

Either way, the docs/website should reflect the latest state I think :) On this page https://www.ethereum.org/greeter it still assumes you're using solc.

ropod7 commented 7 years ago

eth_compileSolidity, or analogue should be available over RPC . Please.

ghost commented 7 years ago

If the old console command has to go, can we not just replace it with a similarly named function that calls a solidity compiler? It just seems sensible that it's there. Or at least, make a tutorial for writing and making solidity apps that people can follow.

I was trying to hard to learn how to use geth or ethereum or anything. All the introductions I can find use Solidity [1]. This system is hard enough to follow or install as it is without all the documentation leading us down dead ends after DAYS AND DAYS of trying to install compilers that apparently don't exist now. So how are we meant to make or deploy smart contracts? This crypto tool has amazing potential but the impossibility of learning how to use or interact with it is terrible.

I can run geth as a fast node on my windows 10 machine, and I have a command-line solc compiler on my MacBook. But I don't seem to be able to get both at once!

Windows10: For example chocolaty now doesn't work, despite tutorials telling me its by far the easiest way to get solc on Windows. If instead I run ">npm install -g solc" ([2]) it seems to work but then when I run ">solc" it just says it's not recognised as a command, program or batch file. Running ">npm install solc" I get a series of warnings, starting with "npm WARN enoent ENOENT: no such file or directory, open 'LocalDir/package.json'".

MacBook: I think solc is working in Terminal, but without a tutorial I'm stuck with rookie errors in even compiling the "Hello World" of [1]. I describe this issue below.

[1] https://ethereum.org/greeter#getting-other-people-to-interact-with-your-code [2] https://solidity.readthedocs.io/en/develop/installing-solidity.html


/* Rookie error with compiling my first solidity program. */
SolidityProjects$ cat helloWorld.sol
pragma solidity ^0.4.1

contract mortal {    
    /* Define variable owner of the type address*/
    address owner;

    /* this function is executed at initialization and sets the owner of the contract */
    function mortal() { owner = msg.sender; }

    /* Function to recover the funds on the contract */
    function kill() { if (msg.sender == owner) selfdestruct(owner); }
}

contract greeter is mortal {
    /* define variable greeting of the type string */
    string greeting;

    /* this runs when the contract is executed */
    function greeter(string _greeting) public {
        greeting = _greeting;
    }

    /* main function */
    function greet() constant returns (string) {
        return greeting;
    }
}

SolidityProjects$ solc helloWorld.sol 
helloWorld.sol:8:5: Error: Expected import directive or contract definition.
    function mortal() { owner = msg.sender; }
    ^
SolidityProjects$ 

alphaqiu commented 7 years ago

Sorry, but how to adding my contract into the gethereum in version of geth 1.6.0?

Okey, web3.eth.contract([]).new() just still can be used.

jw122 commented 7 years ago

The greeter tutorial (and the token, crowdfunding ones) is not yet updated for the changes in 1.6.0.

It makes it harder for people who are trying to learn Ethereum to compile and run contracts. Please fix/advise

KGutierrezTome commented 7 years ago

Please bring back the old command line-compilers, they were very useful for testing

dkhatter commented 7 years ago

I too think eth.compile is a great feature, please bring it back to the latest version.

temores commented 7 years ago

many documents tutoriaIs, etc. point to command line compilers this change breaks them,I too spent DAYS trying to make this work. Please bring it back

nakkapeddi commented 7 years ago

Hi all,

Perhaps the following will help you.

To get a feeling of Solidity (not sure how up to date it is, but will give you an idea of syntax): https://learnxinyminutes.com/docs/solidity/

In order to get the "Hello World" smart contract to work, you need to compile it with solc like so: solc -o output --bin --ast --asm test.sol

where test.sol contains

pragma solidity ^0.4.1;
contract mortal {
    /* Define variable owner of the type address*/
        address owner;

            /* this function is executed at initialization and sets the owner of the contract */
                function mortal() { owner = msg.sender; }

                    /* Function to recover the funds on the contract */
                        function kill() { if (msg.sender == owner) selfdestruct(owner); }
                        }

                        contract greeter is mortal {
                            /* define variable greeting of the type string */
                                string greeting;

                                    /* this runs when the contract is executed */
                                        function greeter(string _greeting) public {
                                                greeting = _greeting;
                                                    }

                                                        /* main function */
                                                            function greet() constant returns (string) {
                                                                    return greeting;
                                                                        }
                                                                        }

"output" can be an arbitrary directory on your machine. For more info, go here:

http://solidity.readthedocs.io/en/develop/using-the-compiler.html

Ignore the formatting, as I copied it from @GregoryFenn; the solidity lexer ignores whitespace so it doesn't matter. This will compile your contract.

k26dr commented 7 years ago

I use eth.compile.solidity for a custom deploy script, it was very useful, please bring back.

bl4ck5un commented 7 years ago

Some useful workaround for the moment: https://ethereum.stackexchange.com/questions/15435/how-to-compile-solidity-contracts-with-geth-v1-6

Tectract commented 7 years ago

We're having downstream issues now because of this. Can you put those functions back, please?

brobits commented 7 years ago

Ethereum.org's own greeter example is out of date now, should update the docs to demonstrate the steps to compiling if these functions aren't restored

Tectract commented 7 years ago

This cost me two days of work to work-around. I don't understand why you guys would intentionally make it harder to compile smart-contracts. We're compiling client-side now...

k26dr commented 7 years ago

Since a lot of people are saying they're having a hard time finding a workaround. Here's a code snippet that will get you the same result without eth.compile.solidity

var fs = require('fs');
var exec = require('child_process').execSync;

exec(`solc --bin --abi --optimize -o bin contract.sol`);

var abi = fs.readFileSync('bin/contract.sol:Contract.abi');
var compiled = '0x' + fs.readFileSync("bin/Contract.bin");

Replace all instances of contract.sol with your source filename and all instances of Contract with the name of your contract.

Tectract commented 7 years ago

This solution won't work under react, and it also requires you to have solc installed locally. It won't work with metamask against ethereum mainnet, either.

Here's my solution, see the full code at: www.github.com/tectract/ethdeployer

in the top-level .html file of my create-react-app:

    <script src="./browser-solc.min.js" type="text/javascript"></script>

and then in the code:

function loadWeb3() {
   let web3Injected = window.web3;
   if(typeof web3Injected !== 'undefined'){
     console.log("saw injected web3!");
     web3 = new Web3(web3Injected.currentProvider);
   } else {
     console.log("did not see web3 injected!");
     web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
     //console.debug(web3.eth.accounts);
   }
}

the above snippet detects either the local web3 object or switches to the metamask-provided web3 object, if that exists...

  var compiler;
  setupCompiler(){
    var outerThis = this;
    setTimeout(function(){
      // console.debug(window.BrowserSolc);
      window.BrowserSolc.getVersions(function(soljsonSources, soljsonReleases) {
        var compilerVersion = soljsonReleases[_.keys(soljsonReleases)[0]];
        console.log("Browser-solc compiler version : " + compilerVersion);
        window.BrowserSolc.loadVersion(compilerVersion, function(c) {
          compiler = c;
          outerThis.setState({statusMessage:"ready!"},function(){
            console.log("Solc Version Loaded: " + compilerVersion);
          });
        });
      });
    },1000);
  }

Note, I had to wait for the window.BrowserSolc object to load, which is the reason for the setTimeout there. note also I'm using the lodash lib as "_" here.

Cheers~

k26dr commented 7 years ago

Correct, my script is for server-side compilation via Node, it will not work client side.

Tectract commented 7 years ago

My script works completely client-side :) Totally standalone and no solc install required. Works against testrpc or against mainnet via metamask plugin.

Also see: www.github.com/tectract/ethereum-demo-tools, and www.enledger.io/ethereum-demo-tools, www.enledger.io/EthDeployer

Note I'm linking against this minified, browserified version of browser-solc.min.js:

https://github.com/ericxtang/browser-solc

Cheers~

adimarco commented 7 years ago

Whether or not the compiler functionality is added back to geth, please update the documentation to reflect something that actually works.

As it stands right now, all of the documentation most important to newcomers is horribly broken, and the path to getting a "hello world" smart contract up and running currently goes through this github thread complaining that nothing works. That's not a way to attract more users.

Specifically this - http://ethdocs.org/en/latest/contracts-and-transactions/contracts.html#writing-a-contract is all wrong now.

t2048 commented 7 years ago

Been writing C/C++ for 20 years, Node.JS for about a year, ended up here because all of the "write your first ethereum contract" tutorials don't work. Nice one guys. Guess I'll just waste a ton of time figuring it out.

Tectract commented 7 years ago

Hi there. This might help you along your way :)

https://blockgeeks.com/guides/how-to-learn-solidity/

t2048 commented 7 years ago

@Tectract thank you!

najmasor commented 7 years ago

I also use eth.compile for different projects and would like to have the feature back...

kwaazaar commented 7 years ago

I find it very unprofessional that after two months, no one on the Ethereum team bothered to update the greeter-sample.

Tectract commented 7 years ago

I was angry about this at first, but then I realized that browser-solc usage is a fundamentally better solution for compilation, because it requires neither server-side nor client-side solc installation.

The docs could be updated though, for sure.

iwat commented 7 years ago

This is stupid, bring it back or fix the tutorial.

parunach commented 7 years ago

If an important feature like this is changed, all relevant documents, tutorials, tests etc MUST be updated. One must address, "What is the work around for this?". Otherwise, few can use this. I prefer this approach. Multiple choices must be given for users.

KellerL commented 7 years ago

We would like to have the compile function back too! A colleague and I spend two complete days just to figure out that the function doesn’t work. @parunach I completely agree with you. What is the alternative to compile now?

KidA001 commented 7 years ago

Developer here who is interested in learning about creating applications with ethereum. Every tutorial I've walked through is broken in some way, ended up here after following https://medium.com/@mvmurthy/full-stack-hello-world-voting-ethereum-dapp-tutorial-part-1-40d2d0d807c2 which seemed like a solid tutorial until it threw an error on eth_compileSolidity

It's going to be hard for the ethereum community to continue to gain support if there aren't any solid tutorials and if the org's own tutorials are borked...

Tectract commented 7 years ago

My tutorial works, I use client-side compilation.

https://blockgeeks.com/guides/how-to-learn-solidity/

You can also simply use the EthDeployer with Metamask plugin:

http://www.enledger.io/EthDeployer

2cool4games commented 7 years ago

I don't know if the changes compiling "with testrpc" makes compatibility problems with the Metamask Extension.

I'm following a course on Pluralsight called Blockchain Fundamentals, and I'm having problems on the last two videos. A user posted a comment saying that something broke the compatibility of the course in some way. That's at least how I interpreted it.

I'm trying to run the files that my instructor provided in the course, and everything compiles, migrates, and npm dev's through. But I get a spinning wheel in metamask when I'm trying to create a new smart contract in the course.

I don't know if this is anything related to this, but I know for a fact that being a Smart Contract / Blockchain developer is a select field right now. So saying I'm waiting for the demand of developers to come, is kind of weird. While there is so little content on these subjects of developing a Cryptocurrency and Smart Contract. It's not like mainstream C++.

Tectract commented 7 years ago

related issue, they introduced a BUG this week in the solidity compiler...

https://github.com/ethereum/solidity/issues/2550

Tectract commented 7 years ago

@2cool4games Did you actually connect Metamask to the mainnet? If you are running a localhost node / testrpc node, you can just turn metamask off and the EthDeployer should connect to your local node and run just fine without metamask.

KellerL commented 7 years ago

@Tectract Thanks a lot! You really helped me. It works with truffle on the TestRPC. However it migrates for ages on my own private network, unfortunately I had to cancel it. Is it normal that it takes so long?

Tectract commented 7 years ago

Thanks for this response. As noted above, right now there is a bug in the solidity compiler which throws erroneous warnings, and can prevent EthDeployer from working, temporarily until that bug is fixed either upstream or in EthDeployer itself (downstream). Are you seeing compiler warnings?

Otherwise, can you open the web console and report back on whether any errors are being kicked in the javascript console?

cheers~

Tectract commented 7 years ago

@KellerL you can alos try connecting to your localhost node VIA metamask, that might help you compile / deploy on your localhost node :)

2cool4games commented 7 years ago

@Tectract I am really happy that you have responded to my post. I really really appreciate it! ( ̄▽ ̄)ノ

Yea, I am using testrpc with metamask. In my "Blockchain Fundamentals Course" I also used Ethereum Blockchain Deployments too. I don't know whether to consider it a private or a public Blockchain. I think it's a Private Blockchain accessible to the internet.

I ran my Ethereum Smart contract with testrpc on localhost 8080. I ran both the instructor's and my code, and both didn't work. I just had a spinning wheel in both of them, and it says in Metamask "Contract Published (Failed)"... Everything went correctly in his video, when he used Metamask in the video. Maybe the update did break something, or I'm doing something wrong.

I just seen a spinning circle in Metamask that never ended.

Thanks again :)

Sebastian.

Tectract commented 7 years ago

The default port should be 8545, not 8080... Did you see any errors in the console? Those would be really helpful.

2cool4games commented 7 years ago

@Tectract

My testRPC is on port 8545. And when I truffle compile, migrate, and npm run dev it runs the instructor's code on port 8080 (localhost:8080).

Do you want the error messages from Metamask or Powershell? I would like to provide you the error messages, but I don't know where to look for them / which ones to share.

Also if you want to take a look at my instructors code here's a link: https://drive.google.com/open?id=0B_-lAAL1mo__U0lHM2V3cGgtSzA ... I am looking particularly at folder FoodSafe_WithCreateContract Folder.

Thank you! Have a awesome day!

Sebastian

Tectract commented 7 years ago

please open the browser "developer console", you should see some stuff going through there in the javascript console. Possibly useful error messages :)