1

I'm trying to call a contract method from the web3 interface in node.js (via testrpc) which should return a Boolean value.

contract_instance.my_method()

This outputs an error:

/node_modules/web3/lib/web3/requestmanager.js:61

throw errors.InvalidResponse(result);

Error: AssertionError: The field to must have byte length of 20

I also tried

contract_instance.my_method.call(function(error, result) {  
  console.log(result);
});

That outputs the same error. Whenever I comment out the result log the error disappears. In the testrpc logs the call is registered.

  • what is your function's code? – Badr Bellaj May 21 '17 at 23:24
  • function my_method() constant returns (bool) { return state; } which returns bool private state – Elias May 22 '17 at 15:58
1

Got the problem.

Instead of

var contract_instance = my_contract.at(["0xf6b0fc7bbb00fa5f47de4cd5d92157365276a0d3"]);

I had to use

var contract_instance = my_contract.at("0xf6b0fc7bbb00fa5f47de4cd5d92157365276a0d3");

0

your code doesn't seem to be the source of your error, its seems to be a testrpc problem i advise you to open an issue on their github.

I've deployed a simple contract on Ropsten testnet

pragma solidity ^0.4.2;


        contract test{

            bool private state;
            function my_method() constant returns (bool) { return state; }

        }

calling the my_method using Web3js(+Metamask) it works perfectly :

contract.my_method(function(error, result){
     if(!error)
         console.log("result:"+result)
     else
         console.error("error:"+error);
 });

the whole code test is available here

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.