2

i went throught the greeter example in here https://www.ethereum.org/greeter and i deployed the smart contract under ropsten test net.

Now im trying to call it from a web page using web3.

var greeterAddress = '0xbc15fCDef6F6FAbAd4097816006523626c10a685';
        var abi = [{ constant: false, inputs: [], name: 'kill', outputs: [], type: 'function' }, { constant: true, inputs: [], name: 'greet', outputs: [{ name: '', type: 'string' }], type: 'function' }, { inputs: [{ name: '_greeting', type: 'string' }], type: 'constructor' }];

        var greeter2 = new web3.eth.contract(abi).at(greeterAddress);        

        console.log('Calling the smart contract');
        var result = greeter2.greet();
        console.log(result);

i keep getting while calling:

var result = greeter2.greet();

the following error:

Uncaught TypeError: this._eth.call is not a function
    at c.call (inpage.js:14300)
    at c.execute (inpage.js:14300)
    at send (ex.html:32)
    at HTMLButtonElement.onclick (ex.html:14)

which step should i take to make sure the contract doen't have any initilization problem? For what i have seen by looking around at examples this should work without problems.

More info: I have another piece of code sending ETH to an address and works just fine, so web3 should be properly installed (version is 0.2x.x.)

EDIT Final working solution:

 var greeterAddress = '0xbc15fCDef6F6FAbAd4097816006523626c10a685';
        var abi = [{ constant: false, inputs: [], name: 'kill', outputs: [], type: 'function' }, { constant: true, inputs: [], name: 'greet', outputs: [{ name: '', type: 'string' }], type: 'function' }, { inputs: [{ name: '_greeting', type: 'string' }], type: 'constructor' }];

        var greeter2 = web3.eth.contract(abi).at(greeterAddress);        

        console.log('Calling the smart contract');
        //var result = greeter2.greet();
        //console.log(result);
        greeter2.greet(function (error, result) {
            if (!error)
                console.log(result)
            else
                console.error(error);
        });
1

Check if your function greet() has either constant, either view or pure access modifier. You can not call function that can modify contract data.

UPDATE: Another suggestion: try not to use new keyword while binding the contract. Just do

var greeter2 = web3.eth.contract(abi).at(greeterAddress);
  • the function should be alright is this one: function greet() constant returns (string) { return greeting; } – user1964154 Dec 5 '17 at 8:53
  • also trying to call that same function in remix.ethereum.org seems to work fine as well – user1964154 Dec 5 '17 at 9:00
  • @user1964154 take a look at update – Alexey Barsuk Dec 5 '17 at 9:10
  • this worked, i just edited with the working solution on my starter message, thank you for the assistance – user1964154 Dec 5 '17 at 9:48

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.