From Library contract method failing #2831:
You probably run geth with the --dev option to create a private network? In that case use the init subcommand to create a private chain. Instructions can be found in the wiki. Or use the testnet.
The problem is that this code uses the delegatecall which is added in the homestead release. The --dev flag uses the homestead block number of the mainnet which is 1150000. Any transaction before this block will encounter an invalid opcode, consumes all gas and all state changes are reverted.
To work around this issue:
...
The genesis config file supports a config section. Currently the only thing you can configure is the homestead block number. If you don't specify it, it will be defaulted to the mainnet number which is 1150000. So basically your contract will work after this block.
Try the following genesis file:
{
"config":{
"homesteadBlock":"5"
},
"nonce":"0x0000000000000042",
"timestamp":"0x0",
"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData":"0x0",
"gasLimit":"0x8000000",
"difficulty":"0x400",
"mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase":"0x3333333333333333333333333333333333333333",
"alloc":{
}
}
If the contract is deployed in block <5 it will give the gas limit problem.
Deployed in block >= 5 it should work as intended.
Further information on using the genesis file can be found at geth init, what are the arguments?.
Update 10:33 Oct 14 2016
I have set up my private blockchain using the following procedures:
1. Setup genesis.json
Wocket:ESE bok$ more genesis.json
{
"config": {
"homesteadBlock": 10
},
"nonce": "0",
"difficulty": "0x400",
"mixhash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
"coinbase": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit": "0x3B4A1B44",
"alloc": {}
}
2. Password file
I created a password file testpassword containing my account password
3. Blockchain Initialisation Script
I created a script to initialise my blockchain:
Wocket:ESE bok$ more 02_runGethGenesisInit
#!/bin/sh
geth --datadir /Users/bok/ESE/gethgenesis init /Users/bok/ESE/genesis.json
geth --datadir /Users/bok/ESE/gethgenesis --password testpassword account new
And I used chmod 700 02_runGethGenesisInit to set the executable bit.
4. Private Node Script
I created a script to start my private geth node in mining mode:
Wocket:ESE bok$ more 02_runGethGenesis
#!/bin/sh
geth --datadir /Users/bok/ESE/gethgenesis --unlock 0 --password /Users/bok/ESE/testpassword --rpc --rpccorsdomain '*' --mine --minerthreads 1 console
And I used chmod 700 02_runGethGenesis to set the executable bit.
5. Browser Solidity
I downloaded Browser Solidity from https://github.com/ethereum/browser-solidity/tree/gh-pages.
I unzipped the files and loaded index.html into my web browser.
6. Start it all
I initialised my blockchain data using the following command:
Wocket:ESE bok$ ./02_runGethGenesisInit
I started my node using the following command, and have been running it for a while:
Wocket:ESE bok$ ./02_runGethGenesis
...
I1015 09:56:14.364062 miner/worker.go:342] Mined block (#5210 / f881b1be). Wait 5 blocks for confirmation
I1015 09:56:14.364333 miner/worker.go:539] commit new work on block 5211 with 0 txs & 0 uncles. Took 281.474µs
I1015 09:56:14.364360 miner/worker.go:435] Mined 5 blocks back: block #5205
I1015 09:56:14.364492 miner/worker.go:539] commit new work on block 5211 with 0 txs & 0 uncles. Took 114.592µs
I1015 09:56:16.394886 miner/worker.go:342] Mined block (#5211 / 420c7edc). Wait 5 blocks for confirmation
I1015 09:56:16.395189 miner/worker.go:539] commit new work on block 5212 with 0 txs & 0 uncles. Took 262.993µs
I1015 09:56:16.395222 miner/worker.go:435] Mined 5 blocks back: block #5206
7. Testing For The Homestead Mode
I loaded the test script by @TjadenHess from How could I update default homesteadBlock value on my private Ethereum blockchain? into Solidity Browser:
contract TestHomestead{
function test () returns(bool){
return address(4).delegatecall(1);
}
}
I connected Solidity Browser to my local private node by clicking on the block icon and selecting Web3 Provider. I then clicked on Create to deploy the contract above to the blockchain. I clicked test and the message Transaction cost: 21657 gas. shows that my blockchain is in Homestead mode.


Note: If I alter the function to make it a constant function test () constant returns(bool){, I get the following results for a Homestead mode blockchain - true:

See section 9. below for the message displayed when the blockchain is in non-Homestead mode.
8. Testing The Library Call Source Code
I've modified the library call source code slightly to make the value variable public, and loaded this into Browser Solidity :
library Library {
function func () constant returns (uint8) {
return 5;
}
}
contract Contract {
uint8 public value;
function call_library_function () {
value = Library.func();
}
}
I clicked Create to deploy the code, call_library_function to execute the method, and value to view the library call function result:


Success
The message Transaction cost: 41914 gas. and the value of value shows that the library function call succeeded.
9. What Happens When My Node Is In Non-Homestead Mode
I connected Browser Solidity with a geth --dev blockchain:
geth --dev --datadir /Users/bok/ESE/gethdata --unlock 0 --password /Users/bok/ESE/testpassword --rpc --rpccorsdomain '*' --mine --minerthreads 1 console
I ran the same Homestead test code to produce the message Gas required exceeds limit: 50000000 showing that this --dev blockchain is in non-Homestead mode:

Note: If I alter the function to make it a constant function test () constant returns(bool){, I get the following results for a non-Homestead mode blockchain - false:

list.append("abc","111");and check how much gas it takes. Then add 10% more and see if this solves your problem.I note that you are writing your code and then deploying into
– BokkyPooBah Oct 11 '16 at 12:44gethdirectly. You should be able to connect Browser Solidity to your localgethinstance by selecting the Web3 Provider in the third icon from the left - refer to the screen image in http://ethereum.stackexchange.com/a/8970/1268.geth, see the step-by-step guide http://ethereum.stackexchange.com/questions/2751/deploying-the-greeter-contract-via-the-geth-cli-is-not-registering-in-my-private for an example on how to specify gas for the contract deployment. – BokkyPooBah Oct 11 '16 at 13:42solc? @BokkyPooBah – alper Jan 02 '17 at 17:16