3

I have a Chainlink node on Kovan testnet. I am following the instructions on https://docs.chain.link/docs/fulfilling-requests page and trying to test my jobs through Testnet Consumer on Kovan.

Oracle contract deployment was successful. Testnet consumer contract deployment was successful. requestEthereumPrice call was successful.

But the currentPrice shows 0.

Here is my code.

pragma solidity 0.4.24;

import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.4/ChainlinkClient.sol";
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.4/vendor/Ownable.sol";

contract ATestnetConsumer is ChainlinkClient, Ownable {
  uint256 constant private ORACLE_PAYMENT = 1 * LINK;

  uint256 public currentPrice;
  int256 public changeDay;
  bytes32 public lastMarket;

  event RequestEthereumPriceFulfilled(
    bytes32 indexed requestId,
    uint256 indexed price
  );

  event RequestEthereumChangeFulfilled(
    bytes32 indexed requestId,
    int256 indexed change
  );

  event RequestEthereumLastMarket(
    bytes32 indexed requestId,
    bytes32 indexed market
  );

  constructor() public Ownable() {
    setPublicChainlinkToken();
  }

  function requestEthereumPrice(address _oracle, string _jobId)
    public
    onlyOwner
  {
    Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(_jobId), this, this.fulfillEthereumPrice.selector);
    req.add("get", "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD");
    req.add("path", "USD");
    req.addInt("times", 100);
    sendChainlinkRequestTo(_oracle, req, ORACLE_PAYMENT);
  }

  function requestEthereumChange(address _oracle, string _jobId)
    public
    onlyOwner
  {
    Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(_jobId), this, this.fulfillEthereumChange.selector);
    req.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
    req.add("path", "RAW.ETH.USD.CHANGEPCTDAY");
    req.addInt("times", 1000000000);
    sendChainlinkRequestTo(_oracle, req, ORACLE_PAYMENT);
  }

  function requestEthereumLastMarket(address _oracle, string _jobId)
    public
    onlyOwner
  {
    Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(_jobId), this, this.fulfillEthereumLastMarket.selector);
    req.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
    string[] memory path = new string[](4);
    path[0] = "RAW";
    path[1] = "ETH";
    path[2] = "USD";
    path[3] = "LASTMARKET";
    req.addStringArray("path", path);
    sendChainlinkRequestTo(_oracle, req, ORACLE_PAYMENT);
  }

  function fulfillEthereumPrice(bytes32 _requestId, uint256 _price)
    public
    recordChainlinkFulfillment(_requestId)
  {
    emit RequestEthereumPriceFulfilled(_requestId, _price);
    currentPrice = _price;
  }

  function fulfillEthereumChange(bytes32 _requestId, int256 _change)
    public
    recordChainlinkFulfillment(_requestId)
  {
    emit RequestEthereumChangeFulfilled(_requestId, _change);
    changeDay = _change;
  }

  function fulfillEthereumLastMarket(bytes32 _requestId, bytes32 _market)
    public
    recordChainlinkFulfillment(_requestId)
  {
    emit RequestEthereumLastMarket(_requestId, _market);
    lastMarket = _market;
  }

  function getChainlinkToken() public view returns (address) {
    return chainlinkTokenAddress();
  }

  function withdrawLink() public onlyOwner {
    LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
    require(link.transfer(msg.sender, link.balanceOf(address(this))), "Unable to transfer");
  }

  function cancelRequest(
    bytes32 _requestId,
    uint256 _payment,
    bytes4 _callbackFunctionId,
    uint256 _expiration
  )
    public
    onlyOwner
  {
    cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);
  }

  function stringToBytes32(string memory source) private pure returns (bytes32 result) {
    bytes memory tempEmptyStringTest = bytes(source);
    if (tempEmptyStringTest.length == 0) {
      return 0x0;
    }

    assembly { // solhint-disable-line no-inline-assembly
      result := mload(add(source, 32))
    }
  }

}

Your help will be highly appreciated!

Job used in Test Consumer Ether Balance

bouteillebleu
  • 2,456
  • 23
  • 32
  • Can you add some more information? 1. What does your node UI look like? 2. Did you `setfulfillmentpermission`? 3. Did you fund your oracle contract with ETH? Please add those statuses to this question. – Patrick Collins Oct 27 '20 at 16:01
  • Thanks for response Patrick! 1. What does your node UI look like? --> Attached screen shot with original quesiton. 2. Did you setfulfillmentpermission? --> Yes, I did. Using my node address and "true" when deploying the Oracle.Sol. 3. Did you fund your oracle contract with ETH? --> Yes, I did. Please see second screen shot. – Bharat Kavade Oct 27 '20 at 22:56
  • Great! A few more benchmarks... Is your node not responding at all? Do you see an error in the "runs" tab? Are you calling the correct jobID and oracle contract in your remix code? Also, I made a mistake in my previous comment. You need your node address funded with ETH not your oracle contract. – Patrick Collins Oct 28 '20 at 00:02
  • Looks like my node is not getting contacted at all. I do not see anything in the job runs tab. Yes, I have checked it multiple times, I am calling correct job ID and Contract in remix. No worries. I got your question. The ETH screen shot is for my node. So Yes, I did fund my node. with 1 ETH. – Bharat Kavade Oct 28 '20 at 00:07
  • https://kovan.etherscan.io/address/0x1E0a09760A2277378b6756115295961cC77c7a7B I don't see any requests going to your oracle contract address. When you call `requestEthereumPrice` what parameters are you sending? – Patrick Collins Oct 28 '20 at 01:48
  • Is that an oracle contract? – Patrick Collins Oct 28 '20 at 01:49
  • 1
    I am sending the "Oracle contract","Job ID" when sending requestEthereumPrice. Where Oracle Contract is the one I deployed it before Test Consumer, having my Node address in setFulfilmentpermission. Here is what I'll do. I'll do the whole process again. If it doesn't work, I'll capture the Etherscan screen shots. That would be more helpful in carrying forward this conversation. What do you think? – Bharat Kavade Oct 28 '20 at 14:29
  • You could do that. It just looks like you're passing the oracle contract and jobId incorrectly. Or maybe you are on the wrong chain in remix or your ETH_URL? – Patrick Collins Oct 28 '20 at 16:56

0 Answers0