-
Is it posible to integrate a price feed that checks Ethereum price inside a checkUpkeep function? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
It is definitely possible, but why? That is not appropriate for checkUpkeep. To keep things modular--and also for reusability--just create a separate contract, or a function inside the main contract. This way you can invoke it inside your checkUpkeep if there is some conditional necessary for checkUpkeep's context--elsewise no; do not include it if it is not appropriate contextually inside checkUpkeep. |
Beta Was this translation helpful? Give feedback.
-
Is this not what I have done, I mean if I'm understanding what you are saying: // SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; // PriceFeed contract imported from chainlink github
library TokenPrice {
/**
* Network: Rinkeby
* Aggregator: ETH/USD
* Address: 0x8A753747A1Fa494EC906cE90E9f37563A8AF630e
*/
function getLatestPrice(AggregatorV3Interface priceFeed) internal view returns (uint256) {
(
/*uint80 roundID*/,
int256 price,
/*uint startedAt*/,
/*uint timeStamp*/,
/*uint80 answeredInRound*/
) = priceFeed.latestRoundData();
return uint256(price);// Retorna 8 decimals
}
function dolarValue(AggregatorV3Interface priceFeed) internal view returns(uint256) {
uint256 Price = getLatestPrice(priceFeed);
uint256 EthAmount = Price/100000000;
return EthAmount;
}
} Which is called by the function: function getPrice() internal returns(uint256) { //Function where I call the conversion
uint256 EthPrice = TokenPrice.dolarValue(priceFeed);
return EthPrice;
} and inside the Also why saying I'm not calling inheritance if I'm using both keepers functions? Solved encodePacking error, thanks! |
Beta Was this translation helpful? Give feedback.
Is this not what I have done, I mean if I'm understanding what you are saying:
Here is the other contract which calls the eth pricefeed.