Solidity Code Compilation

Web3.JS web3.eth.compile.solidity alternatives

林瑋宸 Albert Lin
Coinmonks
Published in
2 min readMay 20, 2018

--

source

Before deploy smart contract, we need to compile solidity code to Bytecode for EVM(Ethereum Virtual Machine). You got two stuff after compiling solidity code:

  • Bytecode/EVM code
  • ABI(Application Binary Interface)

Bytecode is code EVM execute in blockchain network. ABI defines the actions you interact with smart contract. The actions in ABI mean the functions of smart contract.

Bad New

Geth does not support compile solidity code feature (web3.eth.compile.solidity()) since 1.5.9 version above.if you use web3.eth.compile.solidity() in Geth 1.5.9 version above, you will get the error exception. Metamask and TestRPC are also not support compile solidity code.

Alternatives

Here are two ways to solve this problems. The first direct compile solidity code inlocalhost by using Solc(Solidity compiler). it is easy to install Solc in localhost. If your system is ubuntu, you can use apt-get to install Solc. You can reference here if yours is other system.

sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc

You can compile solidity code after installing Solc.

solc [options] [input file …]
solc — bin sample.sol > sample.bin
solc — abi sample.sol > sample.abi
solc — combined-json abi,bin sample.sol > sample.json

Browser Solc

The second way is browser-solc. you can use browser-solc to compile solidity code online. browser-solc is like online solc. I write a simple Online Solc website by using browser-solc here. You can see how it work if you interested. You can put you solidity code into left column and pick the solc version you want to compile.You can see the Bytecode and ABI after enter Compile Code button. source code is here.

--

--

林瑋宸 Albert Lin
Coinmonks

A Novice of Blockchain, Ethereum and Smart Contract.