1

I am using the example from chainlink to call an API; however, I am not sure it does.

function checkProof(string memory JobLocation, int job_id) public {
   Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(JOBID), address(this), this.fulfill.selector);

req.add("get",JobLocation);

req.add("path", "proof");

sendChainlinkRequestTo(ORACLE_ADDRESS, req, ORACLE_PAYMENT); }

I know it calls the following function

 function fulfill(bytes32 _requestId, bool _isProofCorrect, unit val) public recordChainlinkFulfillment(_requestId){
        customers[1].proof = _isProofCorrect;
 }

But, what does selector do in the above code (this.fulfill.selecor)?

Patrick Collins
  • 11,186
  • 5
  • 44
  • 97
Emrah
  • 1,654
  • 2
  • 9
  • 24

1 Answers1

1

what does selector do in the above code (this.fulfill.selecor) ?

In your buildChainlinkRequest function, it takes 3 arguments:

  • bytes32 _specId
  • address _callbackAddress
  • bytes4 _callbackFunctionSignature

The bytes4 _callbackFunctionSignature tells the Chainlink node what method to call when it returns the data. It is known as a function selector, and it allows the node to specify exactly what it needs to call back, in your case the fulfill function.

Also, how can I pass an argument to the fulfill function? I am trying to update the proof variable of my customers map by using what chainlink calls.

Patrick Collins
  • 11,186
  • 5
  • 44
  • 97
  • As you suggested, I created another question. I would really appreciate if you can help with that https://ethereum.stackexchange.com/questions/90643/how-to-pass-argument-to-chainlink-selector – Emrah Nov 30 '20 at 14:57
  • Great, I edited your question so it only reflected the singular question. – Patrick Collins Nov 30 '20 at 15:01