I want to create contract in go-ethereum using Solidity, I started with "Hello world" program.
I create a private network:
$geth --genesis private.json --networkid 1234 --datadir /home/user/Documents/genesisdata console
In here, I make a new account then I coded follow link https://www.ethereum.org/greeter.
var greeterSource ='contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) selfdestruct(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() returns (string) { return greeting; } function test() returns (string){ return greeting; } }'
And I got: undefined
When I code without var like this:
greeterSource ='contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) selfdestruct(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() returns (string) { return greeting; } function test() returns (string){ return greeting; } }'
I got:
"contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) selfdestruct(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() returns (string) { return greeting; } function test() returns (string){ return greeting; } }"
So I continute code without var, I compile:
greeter = greeterContract.new(_greeting,{from:web3.eth.accounts[0], data: greeterCompiled.greeter.code, gas: 210000}, 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);
}
}
else{
console.log("Error:>>>>>>>>>>>>>");
console.log(e);
}
})
untill:
greeter.greet();
TypeError: 'greet' is not a function at :1:1
I don't know, how to solve it.
Please show me the problem that I make in this process.
Thanks.