Lesson4: Getting error while using fund function from FundMe.sol #5657
-
I'm getting error while calling fund function in FundMe.sol. Here is my FundMe.sol: // SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import "./PriceConverter.sol";
contract FundMe {
using PriceConverter for uint256;
uint256 public minimumUsd = 50 * 1e18;
address[] public funders;
mapping(address => uint256) public addressToAmountFunded;
address public owner;
constructor() {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function fund() public payable {
require(msg.value.getConversionRate() >= minimumUsd, "Didn't send enough ETH");
funders.push(msg.sender);
addressToAmountFunded[msg.sender] += msg.value;
// 20000000000000000
}
function getRateForETH(uint256 ethAmount) public view returns(uint256) {
uint256 answer = ethAmount.getConversionRate();
return answer;
}
function withdraw() public onlyOwner {
for (uint256 funderIndex = 0; funderIndex < funders.length; funderIndex++)
{
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
funders = new address[](0);
(bool callSuccess, ) = payable(msg.sender).call{value: address(this).balance}("");
require(callSuccess, "Call failed");
}
} And here is my PriceConverter.sol // SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
library PriceConverter {
function getPrice() internal view returns(uint256) {
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
(, int256 answer, , ,) = priceFeed.latestRoundData();
return uint256(answer * 1e10);
}
function getConversionRate(uint256 ethAmount) internal view returns(uint256) {
uint256 ethPrice = getPrice();
uint256 ethPriceInUSD = (ethPrice * ethAmount) / 1e18;
return ethPriceInUSD;
}
} After deploying using Sepolia test network, when I call getRateForETH in FundMe, I'm getting this error: call to FundMe.getRateForETH errored: Returned error: {"jsonrpc":"2.0","error":"execution reverted","id":713755768095234} |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Jun 11, 2023
Replies: 1 comment 3 replies
-
@satishnvrn You are using the wrong price feed address for the sepolia network actual is this |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
satishnvrn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@satishnvrn You are using the wrong price feed address for the sepolia network actual is this
0x694AA1769357215DE4FAC081bf1f309aDC325306