I am trying to use Greeting tutorial from
https://www.ethereum.org/greeter but I get the error "TypeError: 'greet' is not a function". Can anyone help. BElow is what I am doing.
Connect to Private Network
geth --datadir G:\Temp\Ethereum\datadir 2>> G:\Temp\Ethereum\my.log console
Link SOLC with GETH
admin.setSolc("I:/Installed/Programming/Ethereum 0.9.41/Release/solc.exe");
Define contracts
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 contracts
var greeterCompiled = web3.eth.compile.solidity(greeterSource);
Unlock Account
personal.unlockAccount("7d56684162242fd7e3312c20207d643135263f69", "mypassword")
Instantiate contracts
var _greeting = "Hello World!"
var greeterContract = web3.eth.contract(greeterCompiled.greeter.info.abiDefinition);
var greeter = greeterContract.new(_greeting,{from:web3.eth.accounts[4], 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);
}
}
})
Call Greeter
greeter.greet();
Error
TypeError: 'greet' is not a function
Comments
Initial look suggests that contract is not mined
var greeter = greeterContract.new(_greeting,{from:web3.eth.accounts[4], data:
Tutorial also says "Since this call changes nothing on the blockchain, it returns instantly and without any gas cost." so I thought there is not need for ether. Although I think i did mine ether for the Account used, but maybe you think something else? I don't know what it means to mine contract. So far I have mined ether for Normal Accounts.
OK so I typed miner.start();. waited a bit and then repeated greeter.greet(); and now it says "Hello World!".