I have a contract that uses Oraclize to query some data. When the query is sent, a global variable address is set to the msg.sender. This is to be able to interact with the query sender in the __callback() function.

However, I have a doubt that, while waiting for the __callback() to be executed, another address may initiate the query, and the global state variable address will be set to that new address, and when the __callback() of the first will be executed, it will interact with a wrong address.

Is this a possible scenario? And, if so, how to prevent it? Maybe by linking the __callback() to the query?

1 Answer 1


Is this a possible scenario?

Yes, it's possible.

And, if so, how to prevent it?

You have to associate each msg.sender value with the ID returned by the oraclize_query() call using a mapping, for example:

mapping(bytes32 => address) senderAddresses;

Then when you call oraclize_query():

bytes32 queryId = oraclize_query(<query>);
senderAddresses[queryId] = msg.sender;

When the callback eventually arrives, you can get the original msg.sender value from the mapping:

function __callback(bytes32 myid, string result) {
    require(msg.sender == oraclize_cbAddress());

    address originalSender = senderAddresses[myid];

    // Do other stuff with originalSender...

  • Thank you, I have tried this, but in order to test it I have created a global state variable address and assigned it the value of senderAddresses[myid]. The result was an address 0x0. I suspect that for some reason the queryId and myid are different.
    – Ruham
    Oct 16, 2018 at 19:04
  • I've summarized the issue here, if you could take a look. ethereum.stackexchange.com/questions/60692/…
    – Ruham
    Oct 16, 2018 at 19:42

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.