【发布时间】:2021-11-28 17:34:19
【问题描述】:
我们正在尝试从 Chainlink 调用 API(使用 ngrok 部署在我的机器上进行测试)。我们正在遵循https://docs.chain.link/docs/advanced-tutorial/ 的教程并使用 Rinkeby 网络。我们唯一更改的是作业 id、oracle id 和返回简单 json 的 API URL。 我们可以看到交易正在发生,甚至扣除了 0.1 LINK 的费用。 但是没有调用 API(我们知道这一点是因为我可以看到 API 的实时日志),因此智能合约中也没有获取响应值。
如何调试这个?有没有办法查看作业日志?
以下是我的合约代码:
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;
import "@chainlink/contracts/src/v0.7/ChainlinkClient.sol";
/**
* THIS IS AN EXAMPLE CONTRACT WHICH USES HARDCODED VALUES FOR CLARITY.
* PLEASE DO NOT USE THIS CODE IN PRODUCTION.
*/
contract APIConsumer is ChainlinkClient {
using Chainlink for Chainlink.Request;
uint256 public temperature;
address private oracle;
bytes32 private jobId;
uint256 private fee;
constructor () {
setPublicChainlinkToken();
oracle = 0x46cC5EbBe7DA04b45C0e40c061eD2beD20ca7755;
jobId = "60803b12c6de4443a99a6078aa59ef79";
fee = 0.1 * 10 ** 18; // 0.1 LINK (Varies by network and job)
}
function requestVolumeData() public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
request.add("get", "http://my-api.com");
request.add("path", "temperature");
// Multiply the result by 1000000000000000000 to remove decimals
// int timesAmount = 10**18;
// request.addInt("times", timesAmount);
// Sends the request
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of int
*/
function fulfill(bytes32 _requestId, uint256 _temperature) public recordChainlinkFulfillment(_requestId) {
temperature = _temperature;
}
// function withdrawLink() external {} - Implement a withdraw function to avoid locking your LINK in the contract
}
【问题讨论】:
标签: blockchain solidity smartcontracts chainlink