entropic nova
entropic nova

Reputation: 31

Chainlink - Job not being fulfilled

I've been learning the Chainlink API and trying to build a simple contract that will make an external call to an API and charge the user based on the result of the request from the Oracle.

For example, "We will charge you $1 if the API results in true and $0.25 if it results in false"

I am running this on the Kovan Testnet, the contract is funded with LINK. The transaction is successful every time I run the "requestCompletedData" function. But the callback/fulfill function never gets ran. I've checked it in various ways.

For reference, it should result completed == true based on the data from the URL.

Here are the Contract Address and Job ID for Chainlink's Kovan test nodes: https://docs.chain.link/docs/decentralized-oracles-ethereum-mainnet/

// 
constructor() public {
        setPublicChainlinkToken();
        oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e;
        jobId = "6d914edc36e14d6c880c9c55bda5bc04";
        fee = 0.1 * 10 * 18; // 0.1 LINK
    }

    // Make Chainlink request
    function requestCompletedData() public returns (bytes32 requestId) {
        Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
        
        // URL for request
        request.add("get", "https://jsonplaceholder.typicode.com/todos/4");
        
        // Path to the final needed data point in the JSON response
        request.add("path", "completed");
        
        return sendChainlinkRequestTo(oracle, request, fee);
    }

function fulfill(bytes32 _requestId, bool _completed) public recordChainlinkFulfillment(_requestId) {
        validateChainlinkCallback(_requestId);
        completed = _completed;
    }

Thank you for your help!

Upvotes: 3

Views: 812

Answers (1)

Zak Ayesh
Zak Ayesh

Reputation: 631

Remove the validateChainlinkCallback(_requestId) line in your fulfill() method and it will work.

function fulfill(bytes32 _requestId, bool _completed) public recordChainlinkFulfillment(_requestId) {
        completed = _completed;
    }

The fulfill() method already has the recordChainlinkFulfillment modifier which runs the same validation as the validateChainlinkCallback(_requestId) method anyway.

Reference: ChainlinkClient source code.

Upvotes: 2

Related Questions