Fail to create my first contract

JohnZhangJohnZhang Member Posts: 4
I am new to Ethereum, and following the guide in ethereum website step by step to setup and try.

Now I am blocked in create the first greeter contract...
I use the online Solidity compiler, https://chriseth.github.io/browser-solidity/, to compile the sample greeter contract, and get the content from "Web3 deploy" field in the right.
Then type in the following in geth console:
> var _greeting = "Hello from John";
it prompted "undefined"

> var greeterContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"type":"constructor"}]);
it prompted "undefined"

> var greeter = greeterContract.new(
_greeting,
{
from: web3.eth.accounts[0],
data: 'the compiled data...',
gas: 3000000
}, function(e, contract){
console.log(e, contract);
if (typeof contract.address != 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
});
Then it asked me to input passphrase, after it, it prompted "Account is now unlocked for this session."
After this, it again prompted "undefined", but not the expected "Contract mined! address: .............."

Could you please help tell me what's wrong? many thanks!

Best Regards

John

Comments

  • JohnZhangJohnZhang Member Posts: 4
    As indicated in https://forum.ethereum.org/discussion/3455/how-to-use-online-solidity-compiler

    It is resolved by merge the 2 contracts in tutorial into 1, and then it went well.
  • silly_nsilly_n Member Posts: 7
    Is the Greeter tutorial even (still) valid?

    After I deploy it (greeterContract.new) and mine it, I never seem to be able to get greeter.address ... it is always undefined.
    However, I do see contractAddress via web3.eth.getTransactionReceipt???

    In geth log is see both the tx and address like this:
    I1129 23:17:34.697243 17950 transaction_pool.go:257] (t) 3531303261356466 => [NEW_CONTRACT] (0x536330) 381cf3f9bd56108f20ba6fc4bdb369c7e5ec923aabb0b126c12a7096592180c4 I1129 23:17:34.697332 17950 xeth.go:1053] Tx(0x381cf3f9bd56108f20ba6fc4bdb369c7e5ec923aabb0b126c12a7096592180c4) created: 0xedf4b7d2d88e293b78721d351c241b87a9862ac3 I1129 23:17:34.697343 17950 types.go:106] Generated response: *shared.SuccessResponse &{%!s(float64=26) 2.0 0x381cf3f9bd56108f20ba6fc4bdb369c7e5ec923aabb0b126c12a7096592180c4}


    BTW, I used web3.eth.compile.solidity(greeterSource). No luck with merging the two contracts into one, either.

    Please somebody help :)
  • tokeweedtokeweed Member Posts: 42
    edited November 2015
    silly_n said:

    Is the Greeter tutorial even (still) valid?

    What do you mean by this?

    Edit: It would be nice to have links on news/blog updates on Solidity if you have any.

  • silly_nsilly_n Member Posts: 7
    Well, does the procedure here work for you?
    https://ethereum.org/greeter

    This is my flow:
    --linearize:
    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; } }'

    --compile:
    var greeterCompiled = web3.eth.compile.solidity(greeterSource)
    var _greeting = "Hello World!"

    --instantiate:
    var greeterContract = web3.eth.contract(greeterCompiled.greeter.info.abiDefinition);

    --deploy:
    var greeter = greeterContract.new(_greeting,{from:web3.eth.accounts[1], data: greeterCompiled.greeter.code, gas: 300000}, 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);
    } }})

    --unlocking account and see console msg: Contract transaction send: ... waiting to be mined.
    I mine it and greeter.address is still empty.
  • silly_nsilly_n Member Posts: 7
    Been reading about this problem on reddit and in most cases people's accounts are locked or don't have enough ether. I have unlocked my account with 2 ether in stock. When deploying, the gas is deducted from my account correctly. Which means that all is well and should work, right?

    Still, my greeter.address is left "undefined" and it cannot greet. Again, I do see contractAddress via web3.eth.getTransactionReceipt. Heeelp :)
  • silly_nsilly_n Member Posts: 7
    I managed to solve it, but I think it's a bug (will file an issue today).
    You have to unlock the address when starting geth (geth --unlock). If you unlock it in the console interactively on-the-fly, the contract is not successfully deployed.
Sign In or Register to comment.