0

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!

3
  • Could you give us a link to your ABI? (creat a gist for example) Also, do you use web3js 1 or 0.2? Commented May 27, 2018 at 13:32
  • How are you passing the ABI? It should be passed as a json object, if you send a string it will error out, you can use JSON.parse(abi_as_string). Also which version of web3js are you using? They have different ways to instantiate contracts.
    – Ismael
    Commented May 27, 2018 at 13:51
  • Yeah i was passing the correct ABI in json format directly from Remix, i still am unsure as to why this didnt work but Ive gotten around the problem now by using .getData(param)
    – kquinn
    Commented May 28, 2018 at 14:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.