Hello iam trying to get the latest price data using Chainlink Data Feeds but it throws this error :

pragma solidity 0.7.6;
// SPDX-License-Identifier: MIT

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "contracts/Token.sol";

contract DonateContract {
AggregatorV3Interface internal priceFeed;
address payable owner; // contract creator's address

constructor() {

priceFeed = 
owner = payable(msg.sender); // setting the contract creator


function donate(uint256 _payAmount) public payable  {

(bool success,) = owner.call{value: _payAmount}("");
 require(success, "Failed to send money");
 CRON token = CRON(0x2F718Bc4390F8662bB664D1FDd88494ac6bE71eC);
 uint256 cost =  _payAmount * 6 * priceFeed.latestRoundData ;


  • The error and the code doesn't seem to match. Maybe post the exact code along with the error in the description.
    – Meet
    Mar 14, 2022 at 2:57
  • Please update the question with the correct code and delete the answer with the code, since its not an answer
    – Julissa DC
    Mar 14, 2022 at 17:44
  • Hi phil! Welcome to Ethereum Stackexchange! Please, always include source code as text it makes testing much easier.
    – Ismael
    Mar 15, 2022 at 5:33

1 Answer 1


Two things:

  1. priceFeed.latestRoundData() returns 5 data points:
uint80 roundID,  
int price,  
uint startedAt,
uint timeStamp,
uint80 answeredInRound

I'm assuming you want just the price which you can isolate with a line like this in your code:
(,int price,,,) = priceFeed.latestRoundData();

  1. price is of type int while your cost and _payAmount variables are of type uint. I recommend changing them to type int to match the feeds type. If you really need to you can typecast the price variable to uint or your cost and _payAmount variables to int with a line like this:
    int cost = int(_payAmount) * 6 * price;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.