这是我使用的 API 的文档。
正如您在此图像参考中看到的那样,价格仍显示为 0 。
这是我的代码:
pragma solidity ^0.6.0;
import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol";
contract APIConsumer is ChainlinkClient {
event below20(uint _price);
event below30(uint _price);
event below40(uint _price);
event below50(uint _price);
uint256 public Price;
address private oracle;
bytes32 private jobId;
uint256 private fee;
constructor() public {
setChainlinkToken(0x326C977E6efc84E512bB9C30f76E30c160eD06FB);
oracle = 0xb33D8A4e62236eA91F3a8fD7ab15A95B9B7eEc7D;
jobId = "da20aae0e4c843f6949e5cb3f7cfe8c";
fee = 10 ** 16; // 0.01 LINK
}
function requestBTCCNYPrice() public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
// Set the URL to perform the GET request on
request.add("get", "https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=BTC&to_currency=CNY&apikey=demo");
string[] memory path = new string[](2);
path[0] = "Realtime Currency Exchange Rate";
path[1] = "5. Exchange Rate";
request.addStringArray("path", path);
request.addInt("times", 10000000000);
// Sends the request
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfill(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId)
{
Price = _price;
}