1

How do I get the msg.sender of the user who called randomNumber() in the __callback?

pragma solidity ^0.5.11;

import "github.com/provable-things/ethereum-api/provableAPI_0.4.25.sol";

contract ExampleContract is usingProvable {
 function __callback(bytes32 myid, string result) {
  if (msg.sender != provable_cbAddress()) revert();
  // how do i get the address of the user who called "randomNumber"?
 }

 function randomNumber() public {
  provable_query("WolframAlpha", "random number between 0 and 100");
 }
}

documentation: https://docs.provable.xyz/#ethereum-quick-start

1

You can to implement your own solution. For example using a mapping to link queryId and message's sender.

mapping (bytes32 => address) requests;

function randomNumber() public {
    bytes32 queryId = provable_query("WolframAlpha", "random number between 0 and 100");
    requests[queryId] = msg.sender;
}

You know who send the query using the mapping

function __callback(bytes32 myid, string result) {
    if (msg.sender != provable_cbAddress()) revert();
    address sender = requests[myid];
}
| improve this answer | |

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.