0

I have the following contract that uses Oraclize:

contract Test is usingOraclize {

bytes32 public query;

mapping (bytes32=> address) senderAddress;

address public resultAddress;

function sendQuery() public payable {

  string memory queryString = "some query stringified JSON..."
  bytes32 queryId = oraclize_query("nested", queryString, 235000);

  senderAddress[queryId] = msg.sender;
  query = queryId
}

function __callback(bytes32 myid, string result, bytes proof) {

  resultAddress = senderAddress[myid];

}

}

Now, this works just fine in terms of sending a query and getting a result. However, when I get the resultAddress state variable, it is equal to 0x0 instead of showing the mapped query msg.sender address. Furthermore, if I create a global variable for myid and then store the value in it, it is different from the queryId. I suppose the issue is that since myid and queryId are different, the needed address is not found in the mapping.

What am I missing here?

UPD: It looks like everything is working fine in testnets, and the issue is in JavaScriptVM of the Remix browser. I wonder if there's a way to fix this...

  • Have you tried reading from senderAddress directly? Add a getter function and use the queryId to look at the mapping. – Shawn Tabrizi Oct 16 '18 at 19:44
  • Didn't quite get what you suggest. Also, updating the issue with some more info. – Ruham Oct 16 '18 at 19:46
  • Are you testing on one of the public test networks, or are you using Ganache with Ethereum Bridge? If the former, can you send us the address of your contract? – Richard Horrocks Oct 16 '18 at 19:47
  • On the public test networks everything is fine. I'm not using Ganache and Eth Bridge yet. This is the JavascriptVM and Oraclize plug-in of the Remix browser. The thing is, that the contract actually works and does what is needed if I use a global state variable instead of a mapping. Somehow it works, yet the queryId and myid values are different. – Ruham Oct 16 '18 at 19:52
  • Ah, okay, in that case ignore my answer below. Possible gas or callback price issue? Although I'd expect that the callback wouldn't even arrive in that case... – Richard Horrocks Oct 16 '18 at 19:54
1

It looks like everything is working fine in testnets, and the issue is in JavaScriptVM of the Remix browser. I wonder if there's a way to fix this...

If you're testing locally you'll need to do a bit of work to integrate your test environment with Oraclize. You have two options:

  1. Use Oraclize's own version of Remix, which has a built-in bridge to their oracle services: http://dapps.oraclize.it/browser-solidity/#version=soljson-v0.4.25+commit.59dbf8f1.js
  2. Use Remix, but connect it to a background instance of Ganache, and run your own instance of Ethereum Bridge to interact with Oraclize: https://github.com/oraclize/ethereum-bridge

Note that if you go the way of the first option, you may need to play around with the compiler version. I seem to remember there were problems with getting it to work with anything later than 0.4.20. (Someone who's used it more recently than me can correct me with any updates.)

  • Thank you, I did have problems with the Oraclize's version of Remix, didn't bother to play with it as needed. I will try the Eth Bridge / Ganache now, but the issue is amusing, since the contract actually works even if the ID values are different (if I use global state vars to link query and __callback()). – Ruham Oct 16 '18 at 19:54
0

Apparently, this is a bug in the Remix browser JavascriptVM, since in Ganache / Ethereum Bridge everything is working fine.

Opened a ticket in Oraclize GitHub with a promise of a fix.

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.