How to run the example of `web3.eth.contract`?

Z69BHyAVHQZ69BHyAVHQ Member Posts: 1
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 ()
at web3.js:4227:12
at :1:14


Sign In or Register to comment.