gpt4 book ai didi

nodes - Chainlink 作业没有返回值

转载 作者:行者123 更新时间:2023-12-03 21:54:00 25 4
gpt4 key购买 nike

我有一个预言机和 JobID,我想提交给预言机以获取 ETH 价格数据。我已经资助了该节点,并且正在遵循文档。但是,每次我请求价格时,我的 BTC 值都不会更新。契约(Contract)似乎是由 LINK 资助的,我没有收到 gas 错误,但由于某种原因,这个数字不会改变。到底是怎么回事?

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

在solidity中,小数不起作用,所以每当你从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);
_;
}
}

关于nodes - Chainlink 作业没有返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62162134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com