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

lilililili
  • 21
  • 1

1 Answers1

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];
}
Ismael
  • 30,570
  • 21
  • 53
  • 96