Hi I have a deployed contract
pragma solidity ^0.4.0;
contract adderr {
int total;
function adder() public {
total = 0;
}
function getTotal() constant returns (int){
return total;
}
function addToTotal(int add) returns (int) {
total = total + add;
return total;
}
function calculateProof(string document) constant returns (bytes32) {
return sha256(document);
}
}
I am trying to call the method addToTotal
, so I do:
var address = Contract address
(This is 100% correct i've triple checked)
var abi = contract abi interface
from remix, then taking line breaks out
var contract = eth.contract(abi).at(address)
Then I call with contract.addToTotal(5)
and get the error
Error: invalid address
at web3.js:3930:15
at web3.js:3756:20
at web3.js:5025:28
at map (<native code>)
at web3.js:5024:12
at web3.js:5050:18
at web3.js:5075:23
at web3.js:4137:16
at apply (<native code>)
at web3.js:4223:16
NOTE: When i try the getTotal
method there is no problem the returns the correct value
I have also tried to do:
var contract = new web3.eth.contract(abi,address)
To instantiate my contract, however this time when i try to call I get the error
TypeError: 'getTotal' is not a function
at <anonymous>:1:1
I have tried called methods with both contract.addToTotal
and contract.methods.addToTotal(5)
Would appreciate any help in this matter!
JSON.parse(abi_as_string)
. Also which version of web3js are you using? They have different ways to instantiate contracts.