I need to call a function that returns the uint value requested by the oracle from another contract function.
I am trying the next... but I think I am going by the bad way. Any solution for that?
The Caller contract code:
pragma solidity 0.5.1; // SPDX-License-Identifier: UNLICENSED contract ETHPriceContract{ function getETHPrice() public view returns(bytes32);} contract CallerPriceRequest{ uint256 public price; ETHPriceContract internal ETHPriceOracle; function initETHPrice(address ETHPriceAddress) public { ETHPriceOracle = ETHPriceContract( ETHPriceAddress ); } function getETHPrice() public{ ETHPriceOracle.getETHPrice(); } function CallerFulfill(bytes32 _requestId, uint256 _price) public{ price = _price; } } The Oracle requester contract code:
pragma solidity ^0.5.1; import "https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/evm-contracts/src/v0.5/ChainlinkClient.sol"; // SPDX-License-Identifier: UNLICENSED contract CallerPriceRequest{ function CallerFulfill(bytes32 _requestId, uint256 _price) public; } contract ChainlinkRequestETHPrice is ChainlinkClient { address public CallerAddress = 0x5592675bf651ED82E30F78D5ebAfb1f7F5D851c7; uint256 public price; address private oracle; bytes32 private jobId; uint256 private fee; CallerPriceRequest internal Caller; constructor() public { Caller = CallerPriceRequest( CallerAddress ); setPublicChainlinkToken(); oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e; jobId = "29fa9aa13bf1468788b7cc4a500a45b8"; fee = 0.1 * 10 ** 18; // 0.1 LINK } function getETHPrice() public returns (bytes32 requestId){ Chainlink.Request memory req = buildChainlinkRequest(jobId, CallerAddress, Caller.CallerFulfill.selector); req.add("get", "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD");//{"USD":1797.12} req.add("path", "USD"); req.addInt("times", 100); return sendChainlinkRequestTo(oracle, req, fee); } }