0

I'm trying to use Chainlink to fetch data from an API. The sample code they provide works fine but doesn't quite suit my needs so I'm trying to tweak it.

I'd like to store the requestId so that I know which request is being handled in the call back, but when I try to save it I only get 0 as the requestId.

I'm just adding this:

// added to Contract object
bytes32 public requestId

.
.
.

// store response instead of just disregarding like in sample code
requestId = sendChainlinkRequest(req, fee);

to the sample code provided here: https://docs.chain.link/docs/api-array-response/

The docs say that it's fine to save the requestId but generally not needed, so I would assume this code should work.

Any help would be appreciated.

1 Answer 1

1

With the latest versions of the ChainlinkClient contracts, the requestID is generated when you call the sendChainlinkRequest function, however its not returned, hence why you get the zero after you send the request.

If you follow the function calls in the v0.8 Chainlink client, you can see the request id is generated and used in the rawRequest function, but it's no longer returned (ie no return statement).

You can still access the generated request ID in your contract callback function, because it is sent back there. You just need to add it into your function definition

   function fulfill(bytes32 _requestId, uint256 _volume) public recordChainlinkFulfillment(_requestId) {
        emit RequestVolume(_requestId, _volume);
        volume = _volume;
    }

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.