Greeter not working

I'm copying the code below into the console. However, my greeter functions are all undefined.
var greeterSource = 'contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }'

var greeterCompiled = web3.eth.compile.solidity(greeterSource)

var _greeting = "Hello World! This is Skynet."
var greeterContract = web3.eth.contract(greeterCompiled.greeter.info.abiDefinition);

var greeter = greeterContract.new(_greeting,{from:web3.eth.accounts[0], data: greeterCompiled.greeter.code, gas: 200000}, function(e, contract){
if(!e) {

if(!contract.address) {
console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");

} else {
console.log("Contract mined! Address: " + contract.address);
console.log(contract);
}

}
})
If I enter "greeter" into the console, I get

{
address: undefined
}
None of the logs in the call back show.

Comments

  • glambethglambeth Member Posts: 7
    If you were able to fix this let me know, having the same problem!
  • thunder_cougarthunder_cougar Member Posts: 4
    edited August 2015
    I was able to fix it. The underlying problem is that none of my accounts were unlocked, so the transaction doesn't go through, because no one's paying.

    I was using
    geth console
    geth attach

    And I was typing my commands into geth attach. geth attach won't prompt you for your password. You can just use

    geth console 2>> PATH_OF_LOG

    to suppress the logs instead of using geth attach. geth console will prompt you for your password before any transaction is sent to the blockchain.
  • glambethglambeth Member Posts: 7
    Thanks for the help thunder. I now get a prompt to unlock my account at least but greeter is still just returning address: undefined and I'm not getting any messages about the contract being mined. Any idea?
  • meetreksmeetreks Member Posts: 59
    have you got enough test ethers in your account?
    try
    getBalance(web3.eth.accounts[0]),"ether")
    and let me know what you get
  • thunder_cougarthunder_cougar Member Posts: 4
    Yea your account actually needs to have ether in it. I'm assuming you are actually deploying it to the real Ethereum network and not a test network.
  • meetreksmeetreks Member Posts: 59
    If you do not have enough ethers, switch to a test geth node. Then just start miner.start() and let it run for a few mins. This will give you enough ethers for mining.
  • CartosysCartosys Member Posts: 2
    I'm attempting to deploy this same contract on a test network, with miner running and with plenty of test ether and still getting "address: undefined" are contracts not able to run on my local test network?
  • ililicililic Member Posts: 1
    @Cartosys - What's your initial gas limit in your genesis.json?

    Try sending a transaction from your account to another random address; if you get
    Exceeds block gas limit
        at InvalidResponse (:-81662:-139)
        at send (:-156322:-139)
        at sendTransaction (:-133322:-139)
        at :1:1
    Then your genesis gas limit is probably too low to create contracts
  • CartosysCartosys Member Posts: 2
    @ililic Thanks for chiming in. I am able to send transactions from one wallet to another without error and balances reflect changes within seconds.

    genesis.json shows "gasLimit": "0x16388"

    not sure how to decipher that...
  • JohnZhangJohnZhang Member Posts: 4
    @cartosys I met the similar problem, and it happened to be resolved by merging code into one contract, instead of having two contracts and inheritance. I dont know why... still very new to ethereum... one point is that I use the online solidity compiler, not sure whether it is not the issue to use local compiler.
Sign In or Register to comment.