2

I would like to be able to use certain data in the callback of an oraclize query that I want to pass in when creating the oraclize query.

Say I have the following function in a contract:

function updateExchangeRate(uint delay, uint userId){
    oraclize_query(delay, "URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD");
    // have the userId value be usable in the oraclize callback function
  }

Is it possible to add data to that query than can be used in the callback function? I want to pass in a userId every time I make an oraclize query that I can then use in the callback function.

Is that possible?

5
  • 1
    You get a request ID back so can't you store that in a mapping with the user ID? Commented Oct 29, 2016 at 22:27
  • 1
    Thomas from Oraclize here, I confirm that the @EdmundEdgar hint is the right way to go! Commented Oct 29, 2016 at 22:30
  • @ThomasBertani how do you get the request id when you make the request to store at that point?
    – Pabi
    Commented Oct 29, 2016 at 22:51
  • Figured it out. Just had to take a quick look at the docs. The request itself returns the id of the request.
    – Pabi
    Commented Oct 29, 2016 at 23:49
  • @Pabi yes indeed! docs.oraclize.it/#ethereum-integration-the-query-id Commented Oct 30, 2016 at 17:40

1 Answer 1

2

Use the query ID that comes back from the request and then store that as a mapping with the user ID. Here is the section in the docs (the link in the comments isn't working): http://docs.oraclize.it/#ethereum-quick-start-the-query-id.

bytes32 queryId = oraclize_query(60, "URL", "json(http://api.fixer.io/latest?symbols=USD,GBP).rates.GBP");

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.