在 solidity 中使用多个 Chainlink 预言机进行去中心化 API 调用

Decentralized API calls using multiple Chainlink oracles in solidity

我正在使用 Chainlink 节点获取智能合约中的数据。我读过我可以选择尽可能多的节点,因为我想将不信任的数据放入我的合同中,但现在对我来说,对每个节点进行 API 调用似乎是一个手动过程,而我的合同很大,包含大量地址和工作 ID。

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);
  }

有没有更好的方法?

您可以使用 precoordinator 来启动节点代理网络,您可以假装它本身就是一个 oracle。

预协调器允许您选择要接收 API 调用的任何节点,并将我们的调用发送到每个节点。这样你就可以通过一个请求向多个节点发出一个链链接请求。

您可以通过运行此代码部署预协调器:

pragma solidity ^0.5.0;
import "github.com/smartcontractkit/chainlink/evm-contracts/src/v0.5/PreCoordinator.sol";

或者您可以使用另一个预协调器。一旦有了预协调器合约地址,就可以结合预言机和作业来制定服务协议,这基本上就是节点网络。

                                    ____ Request sent to node
                                   /
Precoordinator -> Service Agreement
                                   \___ Request sent to node

您可以通过与合约交互来创建服务协议。或者直接在 remix 或其他 IDE 中与之交互。