I thought that I had an error similar to this one, that the default account was not set (I was getting method undefined errors for all methods called in my contract).I've set it both in the geth console
eth.defaultAccount = eth.accounts[0]
as well as the js code using geth:
web3 = new Web3(new Web3.providers.HttpProvider(`http://${gethServer.host}:${gethServer.port}`));
/*
Strange bug. Need to specify the account the transactions are made from.
*/
web3.eth.defaultAccount = web3.eth.accounts[0];
When calling the methods of this contract:
contract C {
uint[] numbers;
function initNumbers() {
numbers.push(1);
numbers.push(2);
}
function stateChanger(uint a) {
numbers.push(a);
}
function getNumber(uint index) returns (uint) {
if(index >= numbers.length)
return 0;
else
return numbers[index];
}
}
I get the following output in the geth console:
> c.initNumbers({from:web3.eth.accounts[0],gas:4000000000});
"0x76a1882128d64d94a7bad34e656cd83d57d2a1aefc51b99ba5893f8521a1a79e"
> c.stateChanger(3, {from:web3.eth.accounts[0],gas:400000000});
"0x1b7d5ef5d19a553af756790796a094d2ba213454ab056b7696e2f18e636d8ffc"
> c.stateChanger(4, {from:web3.eth.accounts[0],gas:400000000});
"0xd342a49323b7280e1954a9d33ac9bc457a3015768d5059801d2edf1d16585b9b"
> c.getNumber(0);
"0x31295a2a7ea20cee58e6a144039ae46b835110583b6d1b9517228627eb50999c"
> c.getNumber(1);
"0xce4dba582f37c72d58c767a2b9371a9a8ddbc1e63bc6c96eb5f61cc779168f64"
> c.getNumber(3);
"0x065bd993c4c8e86b2046a53f626619020ad550958dca955a40c839bbc9a1d0c7"
Why does geth return transaction hashes instead of integers as defined by the contract interface? Is it broken?
constantkeyword for methods that will change the blockchain state. If you want to return a status, you will have to design your contract to save the state and use a constant function to retrieve this saved state. See also Reading values from a contract: When do I need transactions? - there is an exampleinc()- there can be multiple transactions of this method in a single block so it does not make sense to get a return status from the state-changing method. – BokkyPooBah Aug 01 '16 at 13:33boolvalue in a method that changes the state of the block chain? I've tried with and without theconstantkeyword. Without I get only the tx hash. And with the word I get true but the value is not stored in the block chain as expected. I know this worked before. I'm not sure what happened to geth. – Sebi Aug 01 '16 at 13:54