本文介绍了链接作业未返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Oracle和JobID,我想提交给Oracle以获取ETH价格数据。我已经为该节点提供了资金,并且正在遵循文档。但是,每次我请求价格时,我的BTC值都不会更新。这份合同似乎是由LINK提供资金的,我没有收到汽油错误,但出于某种原因,这个数字不会改变。发生了什么事?

solidity
pragma solidity ^0.6.0;
import "github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract testingData is ChainlinkClient {
  address public owner;
  uint256 public btc;
  address ORACLE =  0xB36d3709e22F7c708348E225b20b13eA546E6D9c;
  bytes32 constant JOB = "f9528decb5c64044b6b4de54ca7ea63e";
  uint256 constant private ORACLE_PAYMENT = 1 * LINK;
  constructor() public {
    setPublicChainlinkToken();
    owner = msg.sender;
  }
  function getBTCPrice()
    public
    onlyOwner
  {
    Chainlink.Request memory req = buildChainlinkRequest(JOB, address(this), this.fulfill.selector);
    req.add("get", "https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=BTC&to_currency=USD&apikey=xxxx");
    string[] memory copyPath = new string[](2);
    copyPath[0] = "Realtime Currency Exchange Rate";
    copyPath[1] = "5. Exchange Rate";
    sendChainlinkRequestTo(ORACLE, req, ORACLE_PAYMENT);
  }
  function fulfill(bytes32 _requestId, uint256 _price)
    public
    recordChainlinkFulfillment(_requestId)
  {
    btc = _price;
  }
  modifier onlyOwner() {
    require(msg.sender == owner);
    _;
  }
}

推荐答案

对于此特定问题,请执行以下操作:

您需要将多路适配器添加到作业中。在getBTCPrice()中添加一行:

run.addInt("times", 100000000);

下面有完整的示例代码,但是这里有一些关于可能发生的情况的提示。

  1. 节点地址不是funded with ETH-您必须与节点操作员联系。
  1. 作业ID或Oracle地址错误-请仔细检查。

  2. 该节点当前已关闭-请询问节点操作员。

  3. 您已被列入黑名单,或未被列入白名单。请与节点操作员联系。


在可靠性方面,小数不起作用,因此每当您从Oracle获取带小数的数字时,都需要添加multiply adapter以便它可以理解。

完整代码如下:

solidity
pragma solidity ^0.6.0;
import "github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract testingData is ChainlinkClient {
  address public owner;
  uint256 public btc;
  address ORACLE =  0xB36d3709e22F7c708348E225b20b13eA546E6D9c;
  bytes32 constant JOB = "f9528decb5c64044b6b4de54ca7ea63e";
  uint256 constant private ORACLE_PAYMENT = 1 * LINK;
  constructor() public {
    setPublicChainlinkToken();
    owner = msg.sender;
  }
  function getBTCPrice()
    public
    onlyOwner
  {
    Chainlink.Request memory req = buildChainlinkRequest(JOB, address(this), this.fulfill.selector);
    req.add("get", "https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=BTC&to_currency=USD&apikey=xxxx");
    string[] memory copyPath = new string[](2);
    copyPath[0] = "Realtime Currency Exchange Rate";
    copyPath[1] = "5. Exchange Rate";
    sendChainlinkRequestTo(ORACLE, req, ORACLE_PAYMENT);
  }
  function fulfill(bytes32 _requestId, uint256 _price)
    public
    recordChainlinkFulfillment(_requestId)
  {
    btc = _price;
  }
  modifier onlyOwner() {
    require(msg.sender == owner);
    _;
  }
}

这篇关于链接作业未返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-17 01:08
查看更多