I'm storing a product's USD value in contract.
mapping (string => uint256) productUSD;
For example, if it's $52 I'd store it as productUSD[_product] = 52;
Now, when people paying in ETH, I want to make sure they sent in a correct converted amount.
i.e. 0.013 ETH
Chainlink's getThePrice()
returns the latest ETH/USD
price and found it was returning like this. price = 348365740274
function getThePrice() public view returns (int) {
(
uint80 roundID,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = priceFeed.latestRoundData();
return price;
}
Simple math, I can drop 8 decimals from 348365740274
and use 3483
to get a converted ETH amount
i.e. 52 / 3483 = 0.0149296583405111 ETH
- how do I calculate this in solidity? not sure how to drop decimals from
348365740274
- how do I verify user has sent correct eth amount? i.e.
require(msg.value >= ...)