Search code examples
ethereumtrufflegeth

Ethereum deployed contract not defined in Geth Javascript console


I cannot access a deployed and mined Ethereum contract on a private network from the Geth Javascript console. Not sure where the issue is, any help is appreciated.

Thank you in advance for your time.

Scenario

I launched my Geth as below

geth --datadir ~/.ethereum/myProject --networkid 1234 --rpc --rpcport 8546 --rpcapi "eth,net,web3" --unlock 0 console

I've deployed and mined an Ethereum contract (to simplify things, I've used the default MetaCoin contract provided by Truffle), and I got the trx and contract address back. I can access it from the Truffle console but if I try from the Geth Javascript console I get an error.

Please refer to the pictures below:

Truffle console

Geth javascript console

Software used

  • Geth (v1.7.3-stable)
  • NodeJS (v6.12.3)
  • TestRPC (v6.0.3 (ganache-core:2.0.2))
  • Truffle (v4.0.5)

Solution

  • Geth does not know about MetaCoin. In Geth console, you need to do:

    var MetaCoin = web3.eth.Contract(metaCoinJsonAbi, itsAddress);
    // or web3.eth.contract depending on the version of Web3
    

    Then you can use it. Refer to this.