'Is there a simpler way to get decentralized data from Chainlink than doing separate multiple API calls through nodes?
I want to get price feed data of ETH in USD in my solidity project I'm testing in Remix. I'm using the Chainlink request data as a guide so that my data can be decentralized.
Right now, I make 3 chainlink requests to different nodes with different URLs and then calculate the median of the three responses to get a decentralized price. It seems like this is a fairly tedious way to do this, is there a simpler way to get this?
function requestEthereumPrice(address _address, bytes32 job_id, string url)
public
onlyOwner
{
Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(JOB_ID), address(this), this.fulfill.selector);
req.add("get", url);
req.add("path", "USD");
req.addInt("times", 100);
sendChainlinkRequestTo(_address, req, ORACLE_PAYMENT);
}
function multipleData() public{
requestEthereumPrice(ORACLE_ADDRESS, JOB_ID);
requestEthereumPrice(ORACLE2_ADDRESS, JOB2_ID);
requestEthereumPrice(ORACLE3_ADDRESS, JOB3_ID);
}
function fulfill(bytes32 _requestId, uint256 _price)
public
// Use recordChainlinkFulfillment to ensure only the requesting oracle can fulfill
recordChainlinkFulfillment(_requestId)
{
currentPriceList[index] = _price;
index = (index + 1) & 3
currentPrice = median();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
