FundMe #5048
Replies: 1 comment
-
Not sure if this will help at all: The getConversionRate function takes in a parameter btcAmount (which is actually the amount of ether sent to the contract) and returns the equivalent value in USD. The function uses the getPrice function to get the latest BTC/USD price from the Chainlink price feed, and then multiplies the price with the btcAmount parameter to get the equivalent USD value. The USD value is returned as a uint256 type. The contract also has a fund function that requires the equivalent USD value of the msg.value to be greater than minUsd, which is set to 501 ether (in wei units). This means that the minimum amount of ether that can be sent to the contract is 501 ether (in wei units), as calculated using the current BTC/USD price from Chainlink's price feed. Note that the contract assumes that the value being sent to the contract is in ether, but the function is called getConversionRate which converts the value to USD based on the BTC/USD price. The name of the function could be misleading if someone was expecting a direct conversion between ether and USD. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What does this mean?
getConversionRate(msg.value)
//SPDX-License-Identifier:MIT
pragma solidity ^0.8.8;
import"@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract FundMe{
uint256 minUsd=501e18;
function fund()public payable{
require(getConversionRate(msg.value)>minUsd,"Not enough!");
}
function getPrice()public view returns(uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43);
(,int256 price,,,) = priceFeed.latestRoundData();
return uint256(price);
}
function getConversionRate(uint256 btcAmount) public view returns(uint256){
uint256 btcPrice=getPrice();
uint256 btcAmountInUsd=(btcPricebtcAmount)/1e18;
return btcAmountInUsd;
}
}
Beta Was this translation helpful? Give feedback.
All reactions