-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFundMe.sol
More file actions
40 lines (22 loc) · 971 Bytes
/
FundMe.sol
File metadata and controls
40 lines (22 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract FundMe {
uint256 public minimumUsd = 5E18;
function Fund() public payable {
require(getConversionRate(msg.value) >= minimumUsd, "didnt send enough ETH");
}
function getPrice() public view returns (uint256) {
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x694AA1769357215DE4FAC081bf1f309aDC325306);
(, int256 price, , , ) = priceFeed.latestRoundData();
return uint256(price * 1e10);
}
function getConversionRate(uint256 ethAmount) public view returns(uint256) {
uint256 ethPrice = getPrice();
uint256 ethAmountInUsd = (ethPrice * ethAmount)/ 1e18;
return ethAmountInUsd;
}
function getVersion() public view returns (uint256){
return AggregatorV3Interface(0x694AA1769357215DE4FAC081bf1f309aDC325306).version();
}
}