Update Apr 23 2017
geth
1.6.0 has a breaking change to remove access to the Solidity compiler from within geth
.
The workaround is detailed in How to compile Solidity contracts within geth with the v1.6.0 **BREAKING CHANGE**?
Note: Solidity 0.4.9 has a breaking change to a lot of old examples
The new Solidity 0.4.9 3 days ago mentions that you have to be "watching out for file prefixes" - https://github.com/ethereum/solidity/releases/tag/v0.4.9 . <stdin>
is the file prefix for "standard input", when no file prefix is specified.
The workaround is to use:
greeterCompiled["<stdin>:greeter"]
instead of:
greeterCompiled.<stdin>:greeter
as the <
character will cause problems in the geth
command line interpreter.
Details
To compile the greeter example using Solidity 0.4.9, you will have to modify your instructions slightly.
Following are the instructions to work-around the standard Greeter example.
Compile your contract:
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; } }';
var greeterCompiled = web3.eth.compile.solidity(greeterSource);
If you now look at your greeterCompiled
variable, you will see that some members are prefixed with <stdin>
, as mentioned in the Question above.
> greeterCompiled
{
<stdin>:greeter: {
code: "0x6060604052341561000c57fe5b6040516102f03803806102f0833981016040528051015b5b60008054600160a060020a03191633600160a060020a03161790555b805161005390600190602084019061005b565b505b506100fb565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061009c57805160ff19168380011785556100c9565b828001600101855582156100c9579182015b828111156100c95782518255916020019190600101906100ae565b5b506100d69291506100da565b5090565b6100f891905b808211156100d657600081556001016100e0565b5090565b90565b6101e68061010a6000396000f300606060405263ffffffff60e060020a60003504166341c0e1b5811461002c578063cfae32171461003e575bfe5b341561003457fe5b61003c6100ce565b005b341561004657fe5b61004e610110565b604080516020808252835181830152835191928392908301918501908083838215610094575b80518252602083111561009457601f199092019160209182019101610074565b505050905090810190601f1680156100c05780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000543373ffffffffffffffffffffffffffffffffffffffff9081169116141561010d5760005473ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b6101186101a8565b60018054604080516020600284861615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561019d5780601f106101725761010080835404028352916020019161019d565b820191906000526020600020905b81548152906001019060200180831161018057829003601f168201915b505050505090505b90565b604080516020810190915260008152905600a165627a7a723058202c65e52fe69886136391b3ad7b56f7b9b5ab3474a50940ab214964258d3133000029",
info: {
abiDefinition: [{...}, {...}, {...}],
compilerOptions: "--combined-json bin,abi,userdoc,devdoc --add-std --optimize",
compilerVersion: "0.4.9",
developerDoc: {
methods: {}
},
language: "Solidity",
languageVersion: "0.4.9",
source: "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; } }",
userDoc: {
methods: {}
}
}
},
<stdin>:mortal: {
code: "0x6060604052341561000c57fe5b5b60008054600160a060020a03191633600160a060020a03161790555b5b609c806100386000396000f300606060405263ffffffff60e060020a60003504166341c0e1b581146020575bfe5b3415602757fe5b602d602f565b005b6000543373ffffffffffffffffffffffffffffffffffffffff90811691161415606d5760005473ffffffffffffffffffffffffffffffffffffffff16ff5b5b5600a165627a7a72305820eca3dc2bc8d6fa1918006106610ba8497fc2dbc338fbd528482ddd442ab88be50029",
info: {
abiDefinition: [{...}, {...}],
compilerOptions: "--combined-json bin,abi,userdoc,devdoc --add-std --optimize",
compilerVersion: "0.4.9",
developerDoc: {
methods: {}
},
language: "Solidity",
languageVersion: "0.4.9",
source: "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; } }",
userDoc: {
methods: {}
}
}
}
}
Using <
on your your geth
JavaScript command line will not work. So here is a temporary workaround. You can access greeterCompiled.<stdin>:greeter:
in geth
JavaScript using the following syntax:
greeterCompiled["<stdin>:greeter"]
So to execute the rest of the example:
var greeter = greeterContract.new(_greeting,{from:web3.eth.accounts[0],
data: greeterCompiled["<stdin>:greeter"].code, gas: 1000000}, function(e, contract) {
if (!e) {
if (!contract.address) {
console.log("Contract transaction send: TransactionHash: " +
contract.transactionHash + " waiting to be mined...");
} else {
console.log("Contract mined! Address: " + contract.address);
console.log(contract);
}
}
})
Best Answer
It seems like a command syntax issue. This works for me:
solc --abi greeter.sol -o build