0

i got ths error in my smart contract for fund

DeclarationError: Undeclared identifier.
--> contracts/FundMe.sol:29:33:
|
29 | (, int256 answer, , ,) = pricefeed.latestRoundData();
| ^^^^^^^^^

this is my code

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.9.0;

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



contract FundMe {

    mapping(address => uint256) public addressToAmountFunded;


    address public owner;
    constructor() public {
        owner = msg.sender;
    }

    function fund() public payable {
        uint256 minimumUSD = 50 * 10 ** 18;
        require(getConversionRate(msg.value)>= minimumUSD, "You need to spend more ETH!");
        addressToAmountFunded[msg.sender] +=msg.value;
    }
    function getVersion() public view returns(uint256) {
        AggregatorV3Interface pricefeed =AggregatorV3Interface( 0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
        return pricefeed.version();
    }
    function getPrice() public view returns(uint256) {
       (, int256 answer, , ,) = pricefeed.latestRoundData();
        return uint256(answer);
    }
    function getConversionRate(uint256 ethAmount) public view returns(uint256) {
        uint256 ethPrice = getPrice();
        uint256 ehtAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;
        return ehtAmountInUsd();
    }
    function WithDraw() public payable {
        msg.sender.transfer(address(this).balance);
    }

}

and this the function were i get the error

function getPrice() public view returns(uint256) { (, int256 answer, , ,) = pricefeed.latestRoundData(); return uint256(answer);

2 Answers 2

2

You got this error because the pricefeed is not declared or visible for the function.

0

Try this, I think it might work.

function getVersion() public view returns(uint256) {
        AggregatorV3Interface pricefeed =AggregatorV3Interface( 0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
        (,int256 answer,,,) = pricefeed.latestRoundData();
        return uint256(answer * 10000000000);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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