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');
greeter2.greet(function (error, result) {
if (!error)
console.log(result)
else
console.error(error);
});
Best Answer
Check if your function
greet()
has eitherconstant
, eitherview
orpure
access modifier. You can notcall
function that can modify contract data.UPDATE: Another suggestion: try not to use
new
keyword while binding the contract. Just do