I have created a private blockchain and trying to create a sample contract given in https://github.com/ethereum/go-ethereum/wiki/Contracts-and-Transactions
I could create, compile and even deploy the contract but when I execute following statement:
myMultiply7.multiply.call(6)
It always returns "0". Am I missing anything?
Steps I did:
- Created a block chain.
- Did some mining so that I can have some ether in my account. As it was a private network, I could get handsome amount of ether in my primary account.
Create and compiled contract in Geth Console as followed:
primaryAccount = eth.accounts[0] source = "contract testA { function multiply(uint a) returns(uint d) { return a * 5; } }" // compile with solc contract = eth.compile.solidity(source).testA // create contract object var MyContract = eth.contract(contract.info.abiDefinition) // extracts info from contract, save the json serialisation in the given file, //contenthash = admin.saveInfo(contract.info, "~/info.json") // send off the contract to the blockchain var mycon = MyContract.new({from: primaryAccount, data: contract.code}, function(error, contract){ if(!error && contract.address) { console.log("Contract mined! address: " + contract.address + " transactionHash: " + contract.transactionHash); } });
Got the address as output but no transaction hash (Could this be a problem??).
Ran following :
var address = "<Address received in above code >";
var Multiply = web3.eth.contract([{constant:false,inputs:[{name:'a',type:'uint256'}],name:'multiply',outputs:[{name:'d',type:'uint256'}],type:'function'}]);
var myMultiply = Multiply.at(address);
myMultiply.multiply.call(9);
But last line always returns "0".
Unable to understand why this is happening. Am I missing certain steps? Do I need to do something else to get the contract executed?
Thanks in Advance.. Madhukar
ifcondition is buggy so that's why you skip logging it: check the example. – eth Jul 25 '16 at 13:03