簡體   English   中英

如何調試 Chainlink 作業任務?

[英]How to debug Chainlink job task?

我們正在嘗試從 Chainlink 調用 API(使用 ngrok 部署在我的機器上進行測試)。 我們遵循https://docs.chain.link/docs/advanced-tutorial/上的教程並使用 Rinkeby.network。 我們唯一改變的是 job id,oracle id 和 API URL,它返回一個簡單的 json。我們可以看到交易正在發生,甚至扣除了 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
}

開始調試 chainlink 作業的最佳方法是查看日志。 查看日志有兩種主要方法。

  1. 如果在 docker 容器中運行:

運行此命令以查找 docker 容器的名稱。

docker ps

然后

docker logs <NAME_OF_DOCKER_CONTAINER>
  1. 讀取log.jsonl文件。 如果您在.chainlink-rinkeby文件夾中創建它,它將位於.chainlink-rinkeby/log.jsonl

否則,您可以讀取正在調試的作業的JSON

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM