Not able to invoke a contract in Ethereum Private chain using geth

0 votes

I used a Greeter contract and compiled it,which generate web3 deploy code as follows:

var _greeting = "This is a contract" ;
var ballot_sol_greeterContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"type":"constructor"}]);
var ballot_sol_greeter = ballot_sol_greeterContract.new(
    _greeting,
    {
 from: web3.eth.accounts[0], 
 data: '0x6060604052341561000c57fe5b6040516103ac3803806103ac833981016040528080518201919050505b5b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b806001908051906020019061008292919061008a565b505b5061012f565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100cb57805160ff19168380011785556100f9565b828001600101855582156100f9579182015b828111156100f85782518255916020019190600101906100dd565b5b509050610106919061010a565b5090565b61012c91905b80821115610128576000816000905550600101610110565b5090565b90565b61026e8061013e6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806341c0e1b514610046578063cfae321714610058575bfe5b341561004e57fe5b6100566100f1565b005b341561006057fe5b610068610185565b60405180806020018281038252838181518152602001915080519060200190808383600083146100b7575b8051825260208311156100b757602082019150602081019050602083039250610093565b505050905090810190601f1680156100e35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561018257600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b61018d61022e565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102235780601f106101f857610100808354040283529160200191610223565b820191906000526020600020905b81548152906001019060200180831161020657829003601f168201915b505050505090505b90565b6020604051908101604052806000815250905600a165627a7a72305820c1f3ef4f75f67078057f269b87485e55352081a112b0c1d16d369e9ec82a99b30029', 
 gas: '4700000'
    }, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
     console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})

I created a javascript file which and tried to load the file using loadScript() it displayed true and then i mined which generate a hex address.

then I stopped the miner and called the contract using greeter.greet().It shows

ReferenceError: 'greeter' is not defined
at <anonymous>:1:1

and on executing

eth.getCode(greeter.address)
ReferenceError: 'greeter' is not defined
at <anonymous>:1:13
Oct 22, 2018 in Blockchain by slayer
• 29,350 points
735 views

1 answer to this question.

0 votes

Hope this helps:

contract mortal {
  /* Define variable owner of the type address*/
  address owner;

  /* this function is executed at initialization and sets the owner of the     contract */
  function mortal() { owner = msg.sender; }

  /* Function to recover the funds on the contract */
 function kill() { if (msg.sender == owner) suicide(owner); }
}

contract greeter is mortal {
 /* define variable greeting of the type string */
 string greeting;

 /* this runs when the contract is executed */
 function greeter(string _greeting) public {
    greeting = _greeting;
 }

 /* main function */
 function greet() constant returns (string) {
    return greeting;
  }
 }

Also while deploying the code :

 >loadScript("firstContract.js")
  INFO [06-27|19:48:01] Submitted contract creation             
 fullhash=0x1037088a27d9cacf9ced417381489ba58658c09e4377ec1f66a9bc24c1f29269 
 contract=0x2c7e7791dfe505c4f3d456d762990558d4cbe171
 null [object Object]
 true
answered Oct 22, 2018 by Omkar
• 69,210 points

Related Questions In Blockchain

0 votes
1 answer

Not able to send ethers in private ethereum network

Your account is locked by default due ...READ MORE

answered Jan 9, 2019 in Blockchain by Omkar
• 69,210 points
874 views
0 votes
1 answer

Not able to connect nodes on Ethereum Private Network using bootnodes.

If you have created the private network ...READ MORE

answered Jan 27, 2019 in Blockchain by Omkar
• 69,210 points
1,620 views
0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 1,367 views
+1 vote
4 answers

How to connect peers to a private network using geth?

Follow the below steps to connect peers ...READ MORE

answered Jul 13, 2018 in Blockchain by slayer
• 29,350 points
13,420 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,709 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,241 views
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,610 points
973 views
+1 vote
2 answers

Not able to create new account in geth for private ethereum network

Looks like the account you are trying ...READ MORE

answered Dec 6, 2018 in Blockchain by Omkar
• 69,210 points
3,542 views
–1 vote
1 answer

Not able to create new account in geth for private ethereum blockchain

personal.newAccount() is not a default geth method. This ...READ MORE

answered Jan 17, 2019 in Blockchain by Omkar
• 69,210 points
3,396 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP