Reputation:
I am using Chainlink nodes to get data in my smart contract. I’ve read I can choose as many nodes as I’d like to get trustless data into my contract, but a the moment it seems to be a manual process for me to make API calls to each node, and my contract is huge, with a massive list of addresses and jobIDs.
solidity
address[] public oracles;
address[] public jobs;
function loop_through() public {
// does a for loop through each oracle and jobID and calls the get_weather_today function with each.
}
function get_weather_today(address _address, bytes32 _jobID)
public
onlyOwner
{
Chainlink.Request memory req = buildChainlinkRequest(_jobID, address(this), this.fulfill.selector);
req.add("get", "weather_URL");
req.add("path", "today");
sendChainlinkRequestTo(_address, req, ORACLE_PAYMENT);
}
Is there a better way?
Upvotes: 0
Views: 429
Reputation: 6131
You can use a precoordinator to launch a network of nodes proxy, that you can pretend is a single oracle itself.
The precoordinator allows you to choose whichever nodes you want to get your API calls, and fans the call our to each node. This way you can make a single chainlink request to multiple nodes with one request.
You can deploy a precoordinator by running this code:
pragma solidity ^0.5.0;
import "github.com/smartcontractkit/chainlink/evm-contracts/src/v0.5/PreCoordinator.sol";
Or you can use another precoordinator. Once you have a precoordinator contract address, you can combine oracles and jobs to make a service agreement, which is basically the node networks.
____ Request sent to node
/
Precoordinator -> Service Agreement
\___ Request sent to node
You can create the service agreement by interacting with the contract. Or interacting with it directly in remix or some other IDE.
Upvotes: 1