简体   繁体   English

如何调试 Chainlink 作业任务?

[英]How to debug Chainlink job task?

We are trying to call an API(Deployed on my machine using ngrok for testing) from Chainlink.我们正在尝试从 Chainlink 调用 API(使用 ngrok 部署在我的机器上进行测试)。 We are following the tutorial at https://docs.chain.link/docs/advanced-tutorial/ and using Rinkeby.network.我们遵循https://docs.chain.link/docs/advanced-tutorial/上的教程并使用 Rinkeby.network。 The only things we have changed are job id, oracle id and API URL which returns a simple json. We can see the transaction happening and even a fee of 0.1 LINK is deducted.我们唯一改变的是 job id,oracle id 和 API URL,它返回一个简单的 json。我们可以看到交易正在发生,甚至扣除了 0.1 LINK 的费用。 But the API is not called(We know this because I can see the realtime logs of the API) and hence the response value is also not fetched in smart contract.但是 API 没有被调用(我们知道这一点是因为我可以看到 API 的实时日志)因此响应值也没有在智能合约中获取。

How to debug this?如何调试这个? Is there a way to check logs of the job?有没有办法检查作业日志?

Below is my contract code:下面是我的合约代码:

// 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
}

The best way to get started debugging chainlink jobs is to look into the logs.开始调试 chainlink 作业的最佳方法是查看日志。 There are 2 main ways to look into the logs.查看日志有两种主要方法。

  1. If running in a docker container:如果在 docker 容器中运行:

Run this command to find the name of the docker container.运行此命令以查找 docker 容器的名称。

docker ps

Then然后

docker logs <NAME_OF_DOCKER_CONTAINER>
  1. Read the log.jsonl file.读取log.jsonl文件。 If you created this in your .chainlink-rinkeby folder, it'll be in .chainlink-rinkeby/log.jsonl如果您在.chainlink-rinkeby文件夹中创建它,它将位于.chainlink-rinkeby/log.jsonl

Otherwise you can read the JSON of the job that you're debugging.否则,您可以读取正在调试的作业的JSON

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM