Chainlink – How to Fix buildChainlinkRequest Function Not Working Properly

chainlinkoraclesremixsolidity

The buildChainlinkRequest line no 47 takes 3 parameters:

  1. JobId
  2. Callback Address
  3. Function to callback to

I have smartcontract1 and smartcontract2. The below mentioned function is inside smartcontract2

function requestVolumeData(string memory _jobId, string memory addrsss, address callBackContract, bytes4 functionSelector) external returns (bytes32 requestId) {
   
    Chainlink.Request memory req = buildChainlinkRequest(
        stringToBytes32(_jobId),
        callBackContract,
        functionSelector
    );

    req.add("publicKey", addrsss);
    return sendChainlinkRequest(req, fee);
}

Code inside smartcontract1 given below,

interface OracleInterfacehere{
 function requestVolumeData(string memory _jobId, string memory addrsss, address callBackContract, bytes4 functionSelector) external returns (bytes32) ;
}


 function requestingdataFromOracle(string memory _jobId, string memory addrsss, address _smartcontract2) public  {
      OracleInterfacehere OracleOwnerGuard = OracleInterfacehere(_smartcontract2);
      OracleOwnerGuard.requestVolumeData(_jobId, addrsss,address(this), this.fulfill.selector);
 }

  function fulfill(
    bytes32 _requestId,
    bool _status
) public recordChainlinkFulfillment(_requestId) {
    status = _status;
}

What I am expecting is as smartcontract1 call "requestVolumeData" (inside smartcontract2) function, the oracle will send data back to "fulfill" function of smartcontract1.
But this is not working as expected

Note : I have followed this approach(Mentioned in the answer by Patrick) StackExchange question

Best Answer

Chainlink.Request memory req = buildChainlinkRequest(
        stringToBytes32(_jobId),
        callBackContract,
        functionSelector
 );

This function is present in the ChainlinkClient contract that you would be using but this is not the issue in the code.

When you call the function sendChainlinkRequest which is also present in the same contract and is the problem.

This functions body actually saves the address from which this function is actually called

bytes memory encodedRequest = abi.encodeWithSelector(
      ChainlinkRequestInterface.oracleRequest.selector,
      SENDER_OVERRIDE, // Sender value - overridden by onTokenTransfer by the requesting contract's address
      AMOUNT_OVERRIDE, // Amount value - overridden by onTokenTransfer by the actual amount of LINK sent
      req.id,
      address(this),
      req.callbackFunctionId,
      nonce,
      ORACLE_ARGS_VERSION,
      req.buf.buf
    );
Related Topic