1

I run the following simple contract

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() constant returns (string) { return greeting; } }'

var greeterCompiled = web3.eth.compile.solidity(greeterSource)

var _greeting = "Hello World!"
var greeterContract = web3.eth.contract(greeterCompiled.greeter.info.abiDefinition);

var greeter = greeterContract.new(_greeting,{from:web3.eth.accounts[0], 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);
  }

}
else
{
  console.log(e);
}
})

and get the following output

Contract transaction send: TransactionHash: 0xd4b3b0e627e54d0c847fe4379a910b5a4cbc883269d88e6964a68e6e6042f30c waiting to be mined...
Contract mined! Address: 0x06b805ac3b28faed4560f2c4a01b1f988644df12
{ _eth: 
   { _requestManager: { provider: [Object], polls: {}, timeout: null },
 getBalance: { [Function] request: [Function], call: 'eth_getBalance' },
     getStorageAt: { [Function] request: [Function], call: 'eth_getStorageAt' },
     getCode: { [Function] request: [Function], call: 'eth_getCode' },
     getBlock: { [Function] request: [Function], call: [Function] },
     getUncle: { [Function] request: [Function], call: [Function] },
     getCompilers: { [Function] request: [Function], call: 'eth_getCompilers' },
     getBlockTransactionCount: { [Function] request: [Function], call: [Function] },
     getBlockUncleCount: { [Function] request: [Function], call: [Function] },
     getTransaction: { [Function] request: [Function], call: 'eth_getTransactionByHash' },
     getTransactionFromBlock: { [Function] request: [Function], call: [Function] },
     getTransactionReceipt: { [Function] request: [Function], call: 'eth_getTransactionReceipt' },
     getTransactionCount: { [Function] request: [Function], call: 'eth_getTransactionCount' },
     call: { [Function] request: [Function], call: 'eth_call' },
     estimateGas: { [Function] request: [Function], call: 'eth_estimateGas' },
     sendRawTransaction: { [Function] request: [Function], call: 'eth_sendRawTransaction' },
     sendTransaction: { [Function] request: [Function], call: 'eth_sendTransaction' },
     sign: { [Function] request: [Function], call: 'eth_sign' },
     compile: { solidity: [Object], lll: [Object], serpent: [Object] },
     submitWork: { [Function] request: [Function], call: 'eth_submitWork' },
     getWork: { [Function] request: [Function], call: 'eth_getWork' },
     coinbase: [Getter],
     getCoinbase: { [Function] request: [Function] },
     mining: [Getter],
     getMining: { [Function] request: [Function] },
     hashrate: [Getter],
     getHashrate: { [Function] request: [Function] },
     syncing: [Getter],
     getSyncing: { [Function] request: [Function] },
     gasPrice: [Getter],
     getGasPrice: { [Function] request: [Function] },
     accounts: [Getter],
     getAccounts: { [Function] request: [Function] },
     blockNumber: [Getter],
     getBlockNumber: { [Function] request: [Function] },
     iban: 
      { [Function]
        fromAddress: [Function],
        fromBban: [Function],
        createIndirect: [Function],
        isValid: [Function] },
     sendIBANTransaction: [Function] },
  transactionHash: '0xd4b3b0e627e54d0c847fe4379a910b5a4cbc883269d88e6964a68e6e6042f30c',
  address: '0x06b805ac3b28faed4560f2c4a01b1f988644df12',
  abi: 
   [ { constant: false,
       inputs: [],
       name: 'kill',
       outputs: [],
       type: 'function' },
     { constant: true,
       inputs: [],
       name: 'greet',
       outputs: [Object],
       type: 'function' },
     { inputs: [Object], type: 'constructor' } ],
  kill: 
   { [Function]
     request: [Function],
     call: [Function],
     sendTransaction: [Function],
     estimateGas: [Function],
     getData: [Function],
     '': [Circular] },
  greet: 
   { [Function]
     request: [Function],
     call: [Function],
     sendTransaction: [Function],
     estimateGas: [Function],
     getData: [Function],
     '': [Circular] },
  allEvents: [Function] }

Now how can i access the functions please give guide to me

I run this line on terminal and geth console but i got the error

greeter.greet();

the error is

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

So please help anyone to fix this problem if i do anything wrong please mention it

or give the example link

1

That callback is being called twice, the first time when you send the creation contract transaction and the second when the contract is actually mined and has an address (when the else fires in the callback function).

You must wait to the logs to appear stating your contract has been mined and has an address. The tutorial says you should wait like a minute, but it really depends on the kind of network you're deploying to: in a private testnet can be faster than in the real ethereum network. Before being mined, your contract is not in the blockchain, so you can't interact with it (and the client side greeter var doesn't have the contract methods yet).

Just check if greet() is a function of greeter before the call to be sure you can actually call it.

If you're just starting with ethereum, I suggest to get an eye on Testrpc

  • where i need to run the greet function terminal ? or geth console? or in js file . And can i integrate the multisignature by using github.com/ethereumjs/testrpc. Please give the suggestion. Now i am going to the contract method for multisignature process but i can't run this contract simple example. if the multisignature possible in Testrpc method it will help to me – Veera Sarma Jul 12 '16 at 9:35
  • web3.js is a javascript component intended to be used on the browser (you can also use it as nodejs component), but geth console also expose a web3.js object. When your contract is deployed, both browser web3 and geth web3 should be able to interact to the contract at the proper address. Keep in mind, however, that if you make a development test using testrpc, you must use testrpc, and no geth, as your rpc web3 provider. I have no experience with testrpc and multisig but testrpc is an ethereum simulator, so it should work – Sergeon Jul 12 '16 at 9:42
0

My problem solved by the version changing of the geth Please see the below link

Transaction w/ invalid nonce

Thank you guyz

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.