Philipp Storz
Philipp Storz

Reputation: 145

Chainlink node, can't get value of bytes32

I created my own eternal Adapter, that retruns a string as result. The node runs the job correctly and woun't give any error. I think the error happens in the smart contract.

Here is my current smart contract, edited from the Chainlink docs.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";

/**
 * Request testnet LINK and ETH here: https://faucets.chain.link/
 * Find information on LINK Token Contracts and get the latest ETH and LINK faucets here: https://docs.chain.link/docs/link-token-contracts/
 */

/**
 * 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;
  
    bytes32 public volume;
    
    address private oracle;
    bytes32 private jobId;
    uint256 private fee;
    
    /**
     * Network: Kovan
     * Oracle: 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8 (Chainlink Devrel   
     * Node)
     * Job ID: d5270d1c311941d0b08bead21fea7747
     * Fee: 0.1 LINK
     */
    constructor() {
        setPublicChainlinkToken();
        oracle = 0x6A968f08Ba673EaD62b54Ec7FC4095213a679E63;
        jobId = "bf7f39c102594b46b8acd2db6c0cc84d";
        fee = 0.1 * 10 ** 18; // (Varies by network and job)
    }
    
    /**
     * Create a Chainlink request to retrieve API response, find the target
     * data, then multiply by 1000000000000000000 (to remove decimal places from data).
     */
    function requestVolumeData() public returns (bytes32 requestId) 
    {
        Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
        
        // Set the URL to perform the GET request on
        
        
        // Set the path to find the desired data in the API response, where the response format is:
        // {"RAW":
        //   {"ETH":
        //    {"USD":
        //     {
        //      "VOLUME24HOUR": xxx.xxx,
        //     }
        //    }
        //   }
        //  }
        request.add("currency", "ETH");
        
        // Multiply the result by 1000000000000000000 to remove decimals

        
        // Sends the request
        return sendChainlinkRequestTo(oracle, request, fee);
    }
    
    /**
     * Receive the response in the form of uint256
     */ 
    function fulfill(bytes32 _requestId, bytes32 _volume) public recordChainlinkFulfillment(_requestId)
    {
        volume = _volume;
    }

    // function withdrawLink() external {} - Implement a withdraw function to avoid locking your LINK in the contract
}

The External Adapter should retrun something like {\"jobRunID\":0,\"data\":{\"account\":\"0xdF392951284e8779C1e2Fdda5b452222\"},\"result\":\"0dF392951284e8779C1e2Fdda5b45224\",\"statusCode\":200}

My Job Data lookies like:

type = "directrequest"
schemaVersion = 1
name = "name"
contractAddress = "0x6A968f08Ba673EaD62b54Ec7FC4095213a679E63"
maxTaskDuration = "0s"
observationSource = """
    decode_log   [type=ethabidecodelog
                  abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)"
                  data="$(jobRun.logData)"
                  topics="$(jobRun.logTopics)"]

    decode_cbor  [type=cborparse data="$(decode_log.data)"]
    fetch        [type=bridge name="yokuPayBeta2" requestData="{\\"id\\": $(jobSpec.externalJobID), \\"data\\": { \\"currency\\": $(decode_cbor.currency)}}"]
    parse        [type=jsonparse path="result" data="$(fetch)"]
    encode_data  [type=ethabiencode abi="(bytes32 value)" data="{ \\"value\\": $(parse) }"]
    encode_tx    [type=ethabiencode
                  abi="fulfillOracleRequest(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes32 data)"
                  data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}"
                 ]
    submit_tx    [type=ethtx to="0x6A968f08Ba673EaD62b54Ec7FC4095213a679E63" data="$(encode_tx)"]

    decode_log -> decode_cbor -> fetch -> parse -> encode_data -> encode_tx -> submit_tx
""" 

If I click on requestVolumeData in remix, the SC gets executed. As response the volume prints 0x00000000000000000000000000000000000000000000000000000000000000

Where is the error and how to solve it?

Upvotes: 1

Views: 383

Answers (1)

Jan Swoboda
Jan Swoboda

Reputation: 172

Send ETH to your chainlink oracle address.

Upvotes: 1

Related Questions