When I compiled following code at "https://ethereum.github.io/browser-solidity/" it gives me two Web3 deploy code for:
var libraryContract = web3.eth.contract(...); //Web3 deploy code
var contractContract = web3.eth.contract(...); //Web3 deploy code
Then I have copy paste Web3 deploy code for (libraryContract, contractContract) into geth in order to mine my contracts.
My code (I have trimmed most of it for simplicity):
library Library {
function func () constant returns (uint8) {
return 5;
}
}
contract Contract {
uint8 value;
function call_library_function () {
value = Library.func();
}
}
"Library"'s Web3 deploy code mines perfectly fine,
but when I try to mine "Contract"'s Web3 deploy code, I get the following error:
> Error: The contract code couldn't be stored, please check your gas amount. undefined
If I remove the following line from my Contract Link code, newly generated "Contract"'s Web3 deploy code mines! without any problem:
value = Library.func();
[Q] My question is, how could I fix this problem I am having? What should I do to call my function inside a Library from a Contract, which will allow me to mine it?
How I did setup my private Ethereum Blockchain:
Please see on the following link:
How could I update default homesteadBlock value on my private Ethereum blockchain?
Thank you for your valuable help and time.
Best Answer
From Library contract method failing #2831:
To work around this issue:
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
2. Password file
I created a password file
testpassword
containing my account password3. Blockchain Initialisation Script
I created a script to initialise my blockchain:
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: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:
I started my node using the following command, and have been running it for a while:
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: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 :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 ofvalue
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: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: