Search code examples
ethereumsoliditychainlink

Reading multiple uint256 entries from same JSON response using a single ChainLink request


I need to parse two different uint256 values from the same JSON response to do a simple calculation. I am currently implementing two different requests (one for each of the uint) using the same chainlink test node and jobID

 /**
 * Receive the response in the form of uint256
 */ 
function fulfillWeight(bytes32 _requestId, uint256 _weight) public recordChainlinkFulfillment(_requestId)
{
    weight = _weight;
}

function fulfillHeight(bytes32 _requestId2, uint256 _height) public recordChainlinkFulfillment(_requestId2)
{
    height = _height;
}

Is there a way of implementing this without resorting to using two different requests, how could I combine parsing the same json response for the two uint256 values under the same request? would I need to search for a specific Node / JobId that carried this out? Thanks !


Solution

  • Great question, what you're looking for is Multi-Word (multi-variable) responses.

    As of right now, you do need to know what the job spec of the Chainlink Job is to know what it's going to return, but you can hop into the Chainlink Discord and request a node create a generic job for you to get your multiple types back.

    This is a brand new Chainlink feature, so documentation is still a little sparse!