TypeError: 'greet' is not a function

ivoronlineivoronline Member Posts: 21
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);

Call Greeter

TypeError: 'greet' is not a function


  • meetreksmeetreks Member Posts: 59
    Can you type just greeter and paste the result here?

    Initial look suggests that contract is not mined
  • ivoronlineivoronline Member Posts: 21
    edited September 2015
    I have noticed then when I paste below code Command Prompt only shows from "web3.eth.accounts[4], data:..." as can be seen from the screenshot at the bottom which is maybe why greeter is not defined. Which is why I also tried putting the code in separate JavaScript file but that didn't help.

    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.
    Post edited by ivoronline on
  • ivoronlineivoronline Member Posts: 21
    edited September 2015
    Aha, so I am the one who is supposed to start mining.
    OK so I typed miner.start();. waited a bit and then repeated greeter.greet(); and now it says "Hello World!".
Sign In or Register to comment.