5

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:

  1. Created a block chain.
  2. 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.
  3. 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

jrbedard
  • 524
  • 1
  • 6
  • 15
MadhukarChaubey
  • 161
  • 1
  • 1
  • 4
  • please format the code better so it can be seen clearer – dragosb Jul 25 '16 at 08:33
  • 2
    Your mining appears fine and you'd get a transaction hash the first time the callback is called, but your if condition is buggy so that's why you skip logging it: check the example. – eth Jul 25 '16 at 13:03
  • A step-by-step guide to deploying a simple contract can be found at http://ethereum.stackexchange.com/questions/2751/deploying-the-greeter-contract-via-the-geth-cli-is-not-registering-in-my-private – BokkyPooBah Jul 25 '16 at 13:38
  • I checked the if condition. It looks fine as I am getting the address part but transactionHash has no values. It is blank. How the transactionhash is generated? Am I missing anything else? – MadhukarChaubey Jul 26 '16 at 10:59
  • if condition should be revisited and improved – Aniket Jul 27 '16 at 13:16

1 Answers1

1

Got the address as output but no transaction hash (Could this be a problem??).

I deduce that you have not mined the contract and therefore it does not exist. If you are on a private net someone has to mine each transaction:

miner.start(); admin.sleepBlocks(1); miner.stop();
Roland Kofler
  • 11,638
  • 3
  • 44
  • 83