How to debug Chainlink job task?

Viewed 174

We are trying to call an API(Deployed on my machine using ngrok for testing) from Chainlink. We are following the tutorial at https://docs.chain.link/docs/advanced-tutorial/ and using 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. 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.

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
}
1 Answers

The best way to get started debugging chainlink jobs is to look into the logs. There are 2 main ways to look into the logs.

  1. If running in a docker container:

Run this command to find the name of the docker container.

docker ps

Then

docker logs <NAME_OF_DOCKER_CONTAINER>
  1. Read the log.jsonl file. If you created this in your .chainlink-rinkeby folder, it'll be in .chainlink-rinkeby/log.jsonl

Otherwise you can read the JSON of the job that you're debugging.

enter image description here

Related