so I have a contract deployed on Ropsten and now I'm trying to access the public variable using a JSON RPC call through Infura and Oraclize.

Here's my contract: contract test_contract { uint public last_a;

function double(uint a) public returns(uint) { 
  last_a = a;
  return 2*a;   

 function getLastA() public constant returns(uint){
     return last_a;

 function getMethod() public constant returns(bytes4){
     return bytes4(keccak256("getLastA())"));

Ok. So I get the method getLastA using the getMethod, pad it to 32, get the contract address on Ropsten...and now this is my call:

url post - json(https://ropsten.infura.io/).result
 params -  {"jsonrpc":"2.0","id":3,"method":"eth_call","params":[{"to":"0x76a83b371ab7232706eac16edf2b726f3a2dbe82","data":"4b9a1598000000000000000000000000000000000000000000000000000000000000000"], "latest"}

You can see my oraclize query here

Just wondering if I'm doing something wrong or if this is even possible. The value it should return is 17 if anyone else thinks they have an answer.

1 Answer 1


There were a few things wrong with your HTTP request:

  1. The JSON was malformed due to a missing curly brace and a mis-placed square bracket.
  2. The data field had the wrong function selector in it.
  3. The data field was missing the leading 0x.
  4. The data field was the wrong length. Although there's no need to pad with zeros, you can do that as long as you get the length right. You had an odd number of digits (71).

Here's a valid JSON payload:

    "id": 3,
    "jsonrpc": "2.0",
    "method": "eth_call",
    "params": [
            "data": "0xad3b80a8",
            "to": "0x76a83b371ab7232706eac16edf2b726f3a2dbe82"

POSTing this to https://ropsten.infura.io yields a result of 0x0000000000000000000000000000000000000000000000000000000000000011 (17 in decimal).

Here's a working Oraclize query: http://app.oraclize.it/home/test_query#VVJMKFBPU1Qp:anNvbihodHRwczovL3JvcHN0ZW4uaW5mdXJhLmlvLykucmVzdWx0:IHsianNvbnJwYyI6IjIuMCIsImlkIjozLCJtZXRob2QiOiJldGhfY2FsbCIsInBhcmFtcyI6W3sidG8iOiIweDc2YTgzYjM3MWFiNzIzMjcwNmVhYzE2ZWRmMmI3MjZmM2EyZGJlODIiLCJkYXRhIjoiMHhhZDNiODBhOCJ9LCAibGF0ZXN0Il19.

Out of curiosity, what's the reason for using Oraclize rather than just calling the contract directly? Are you doing cross-chain communication between contracts?

  • wow...you rock man. And good job with the guess. Just playing around with using oraclize to bridge two chains
    – thefett
    Mar 16, 2018 at 19:45
  • And just curious, does my 'getMethod' not get me the proper function selector?
    – thefett
    Mar 16, 2018 at 19:49
  • Just spotted the issue. You have an extra parenthesis in the string you're hashing. By the way, I think you can just do return this.getLastA.selector.
    – user19510
    Mar 16, 2018 at 19:53
  • Figures..and that is a much easier way. Thanks for the help!
    – thefett
    Mar 16, 2018 at 20:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.