[Ethereum] Compiling contract in web3: “Method eth_compileSolidity not supported”

compilationcontract-deploymentweb3js

I have web3 and truffle running. I am able to execute the following commands:

> node
> Web3 = require('web3')
> web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
> web3.eth.accounts
> code = fs.readFileSync('contracts/Voting.sol').toString()

Then I want to compile the Voting.sol contract with the following command:

> contract =  web3.eth.compile.solidity(code)

This fails with the following error:

Error: Error: Method eth_compileSolidity not supported.
at GethApiDouble.handleRequest (C:\Users\abc\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:85608:16)
at next (C:\Users\abc\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:113129:18)
at VmSubprovider.handleRequest (C:\Users\abc\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:113829:12)
at next (C:\Users\abc\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:113129:18)
at GethDefaults.handleRequest (C:\Users\abc\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:85935:12)
at next (C:\Users\abc\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:113129:18)
at FilterSubprovider.handleRequest (C:\Users\abc\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:113388:7)
at next (C:\Users\abc\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:113129:18)
at DelayedBlockFilter.handleRequest (C:\Users\abc\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:85448:3)
at next (C:\Users\abc\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:113129:18)
at Object.InvalidResponse (C:\Users\abc\truffletest\node_modules\web3\lib\web3\errors.js:38:16)
at RequestManager.send (C:\Users\abc\truffletest\node_modules\web3\lib\web3\requestmanager.js:61:22)
at Object.send [as solidity] (C:\Users\abc\truffletest\node_modules\web3\lib\web3\method.js:145:58)
at repl:1:30
at sigintHandlersWrap (vm.js:22:35)
at sigintHandlersWrap (vm.js:73:12)
at ContextifyScript.Script.runInThisContext (vm.js:21:12)
at REPLServer.defaultEval (repl.js:340:29)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)

I am going off this tutorial https://medium.com/@mvmurthy/full-stack-hello-world-voting-ethereum-dapp-tutorial-part-1-40d2d0d807c2

Best Answer

So essentially, the developers decided that making a node compile a contract like this to be out of scope. So this functionality has been deprecated. There were many reasons behind this, but the main ones are that RPC calls are beyond the responsibilities of the eth API, and node compilation like this is not sufficient. You can use an online compiler like Remix, or a compiler like solc to get the bytecode and go from there.