Chainlink 示例不更新值

发布于 2025-01-17 07:55:38 字数 1975 浏览 2 评论 0原文

我正在遵循 Chainlink 文档(也在下面)中的示例,并且有一直在混音中测试它。我已经在 kovan 测试网和 kovan 测试网上部署了合约。发送链接给它,我能够执行 requestVolumeData() 并获得交易已完成的通知,并且我能够在 etherscan 上查看它。

然而,当检查音量值时,它总是返回 0。我知道这可能需要一些时间,但等待 20 分钟后该值没有改变。

我已经使用以下 oracle 地址/作业 ID 进行了测试。 从例子来看 (0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8 & d5270d1c311941d0b08bead21fea7747) 来自随附的 YouTube 视频 (0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e & 29fa9aa13bf1468788b7cc4a500a45b8) 以及来自 chainlink 市场(设置为 kovan 网络)。 (0xA1d76ABD287d87d6E1d92262F7D53Cbe4f290505 & fc3ea215bb9e44e088107b29bb495e2d)

我不确定哪里出了问题,我不认为这是代码,因为它是从示例复制粘贴的。但这些地址都不起作用。

pragma solidity ^0.8.7;

import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";

contract APIConsumer is ChainlinkClient {
    using Chainlink for Chainlink.Request;
  
    uint256 public volume;

    address private oracle;
    bytes32 private jobId;
    uint256 private fee;

    constructor() {
        setPublicChainlinkToken();
        oracle = 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8;
        jobId = "d5270d1c311941d0b08bead21fea7747";
        fee = 0.1 * 10 ** 18;
    }
    
    function requestVolumeData() public returns (bytes32 requestId) {
        Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
        
        request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");        
        request.add("path", "RAW.ETH.USD.VOLUME24HOUR");
        int timesAmount = 10**18;
        request.addInt("times", timesAmount);
        
        return sendChainlinkRequestTo(oracle, request, fee);
    }
    
    function fulfill(bytes32 _requestId, uint256 _volume) public recordChainlinkFulfillment(_requestId) {
        volume = _volume;
    }
}

I'm following the example within the Chainlink documentation (also below), and have been testing it within remix. I've deployed the contract on the kovan testnet & sent LINK to it, I'm able to execute the requestVolumeData() and get the notification that the transaction was completed and I'm able to view it on etherscan.

However, when checking the value of volume it always returns 0. I'm aware that it can take some time, but the value hasn't changed after waiting 20 minutes.

I've done tests with the following oracle addresses / job id's.
From the example
(0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8 & d5270d1c311941d0b08bead21fea7747)
From the accompanying youtube video
(0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e & 29fa9aa13bf1468788b7cc4a500a45b8)
And from chainlink market (set to kovan network).
(0xA1d76ABD287d87d6E1d92262F7D53Cbe4f290505 & fc3ea215bb9e44e088107b29bb495e2d)

I'm not sure where things go wrong, I don't think it's the code since it's copy pasted from the example. But non of the adreses have worked.

pragma solidity ^0.8.7;

import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";

contract APIConsumer is ChainlinkClient {
    using Chainlink for Chainlink.Request;
  
    uint256 public volume;

    address private oracle;
    bytes32 private jobId;
    uint256 private fee;

    constructor() {
        setPublicChainlinkToken();
        oracle = 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8;
        jobId = "d5270d1c311941d0b08bead21fea7747";
        fee = 0.1 * 10 ** 18;
    }
    
    function requestVolumeData() public returns (bytes32 requestId) {
        Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
        
        request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");        
        request.add("path", "RAW.ETH.USD.VOLUME24HOUR");
        int timesAmount = 10**18;
        request.addInt("times", timesAmount);
        
        return sendChainlinkRequestTo(oracle, request, fee);
    }
    
    function fulfill(bytes32 _requestId, uint256 _volume) public recordChainlinkFulfillment(_requestId) {
        volume = _volume;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

土豪我们做朋友吧 2025-01-24 07:55:38

request.add("path", "RAW.ETH.USD.VOLUME24HOUR"); 行应为 request.add("path", "RAW,ETH,USD,VOLUME24HOUR") ;(注意逗号而不是点)。

Chainlink 节点 1.0.0 及更高版本支持这种新的“基于逗号”的格式。 1.0.0 之前的 Chainlink 节点支持您在原始问题中提供的“基于点”格式。

据我现在所见,官方文档已更新以包含此更改。

Line request.add("path", "RAW.ETH.USD.VOLUME24HOUR"); should be request.add("path", "RAW,ETH,USD,VOLUME24HOUR"); (notice the commas instead of dots).

Chainlink nodes 1.0.0 and later support this new "comma based" format. Chainlink nodes prior to 1.0.0 support the "dots based" format you provided in the original question.

From what I can see now, the official docs have been updated to include this change.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文