Would be useful to add a small note at the beginning of this Wiki paragraph that compilation from within geth JS console is not supported anymore since v1.6.0.
Instead, advise readers to go to http://solidity.readthedocs.io/en/latest/index.html for resources on solidity compilation.
Its not only on that wiki, even the greeter is still using the old method.
Hi all! Here I prepared text for greeter compilation with solc instead of using web3.eth,compile.solidity. I've tested it and it works, only wiki formatting needed. Wiki editors, please fix it.
The Solc Compiler
Before you are able to Deploy it though, you'll need two things: the compiled code, and the Application Binary Interface, which is a JavaScript Object that defines how to interact with the contract.
The first you can get by using a compiler. You should have a solidity compiler installed on your system. Installing ways can be found here: http://solidity.readthedocs.io/en/develop/installing-solidity.html
COMPILING YOUR CONTRACT
Now you have the compiler installed, you need to put your code in file Greeter.sol and compile it.
Compile Greeter.sol in the .json format, assign the data to a JavaScript variable and send the output into a file:
Linux/Mac way:
$ echo "var compilerOutput=solc --optimize --combined-json abi,bin,interface Greeter.sol" > greeter_compiled.js
Windows way:
run command
solc --optimize --combined-json abi,bin,interface Greeter.sol
then save output to file greeter_compiled.js and put at beginning of file following:
var compilerOutput=
Now you have compiler output which you can import as JS object
In geth console, load the contents of greeter_compiled.js and check that compilerOutput is initialized:
> loadScript("FULL_PATH/greeter_compiled.js")
true
> compilerOutput
Set some variables up, like what greeting you want to use.
Execute these command in geth console (you can use something more interesting than "Hello World!"):
> var _greeting = "Hello World!"
Unlock your account
> personal.unlockAccount(eth.accounts[0], "{top secret password}");
true
Finally, deploy contract:
> var greeterContract = web3.eth.contract(JSON.parse(compilerOutput.contracts["Greeter.sol:greeter"].abi));
undefined
var deployed = greeterContract.new(_greeting, { from: eth.accounts[0], data: "0x" + compilerOutput.contracts["Greeter.sol:greeter"].bin, gas: 4700000},
function (e, contract) {
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
}
);
USING THE ONLINE COMPILER
...
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Hi all! Here I prepared text for greeter compilation with solc instead of using web3.eth,compile.solidity. I've tested it and it works, only wiki formatting needed. Wiki editors, please fix it.
The Solc Compiler
Before you are able to Deploy it though, you'll need two things: the compiled code, and the Application Binary Interface, which is a JavaScript Object that defines how to interact with the contract.
The first you can get by using a compiler. You should have a solidity compiler installed on your system. Installing ways can be found here: http://solidity.readthedocs.io/en/develop/installing-solidity.html
COMPILING YOUR CONTRACT
Now you have the compiler installed, you need to put your code in file Greeter.sol and compile it.
Compile Greeter.sol in the .json format, assign the data to a JavaScript variable and send the output into a file:
Linux/Mac way:
$ echo "var compilerOutput=solc --optimize --combined-json abi,bin,interface Greeter.sol" > greeter_compiled.jsWindows way:
run command
Now you have compiler output which you can import as JS object
In geth console, load the contents of greeter_compiled.js and check that compilerOutput is initialized:
Set some variables up, like what greeting you want to use.
Execute these command in geth console (you can use something more interesting than "Hello World!"):
> var _greeting = "Hello World!"Unlock your account
Finally, deploy contract:
USING THE ONLINE COMPILER
...