0

I first start ganache. Then, I run the following commands. But I got the following error. Does anybody know what is wrong? Thanks.

$ geth attach http://localhost:8545
Welcome to the Geth JavaScript console!

instance: EthereumJS TestRPC/v2.1.0/ethereum-js
coinbase: 0x61ee7ad67c57759a03f84d29c5de219ef359016a
at block: 0 (Tue, 10 Apr 2018 16:38:25 CST)
 modules: eth:1.0 evm:1.0 net:1.0 personal:1.0 rpc:1.0 web3:1.0

> var abi = [{
...      name: 'myConstantMethod',
...      type: 'function',
...      constant: true,
...      inputs: [{ name: 'a', type: 'string' }],
...      outputs: [{name: 'd', type: 'string' }]
... }, {
...      name: 'myStateChangingMethod',
...      type: 'function',
...      constant: false,
...      inputs: [{ name: 'a', type: 'string' }, { name: 'b', type: 'int' }],
...      outputs: []
... }, {
...      name: 'myEvent',
...      type: 'event',
...      inputs: [{name: 'a', type: 'int', indexed: true},{name: 'b', type: 'bool', indexed: false}]
... }];
undefined
> var MyContract = web3.eth.contract(abi);
undefined
> var myContractInstance = MyContract.at('0xc4abd0339eb8d57087278718986382264244252f');
undefined
> var result = myContractInstance.myConstantMethod("myParam");
Error: Attempting to run transaction which calls a contract function, but recipient address 0xc4abd0339eb8d57087278718986382264244252f is not a contract address
    at web3.js:3143:20
    at web3.js:6347:15
    at web3.js:5081:36
    at web3.js:4102:22
    at apply (<native code>)
    at web3.js:4227:12
    at <anonymous>:1:14
  • Basically means that the provided address 0xc4ab...44252f doesn't belong to a contract. The contract has been deployed correctly? – mirg Apr 10 '18 at 15:59
  • Looks like a version issue. Web3 is 1.0 via ethereumjs-testrpc but your functions are, or at least appear to be, 0.20.x. There are some subtle differences between the versions for contract functions more of which you can read about here: web3js.readthedocs.io/en/1.0/web3-eth-contract.html – ryanh Apr 10 '18 at 20:33
0

Are you on the Ropsten test network? If so, etherscan shows that the address you provided 0xc4abd0339eb8d57087278718986382264244252f to var myContractInstance is not a contract address. It's a normal address that hasn't been interacted with in nearly a year. To import a deployed contract by its address, the contract has to be deployed first!

See here: https://ropsten.etherscan.io/address/0xc4abd0339eb8d57087278718986382264244252f.

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.