-
Notifications
You must be signed in to change notification settings - Fork 0
/
FundMe.sol
67 lines (53 loc) · 2.23 KB
/
FundMe.sol
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol";
contract FundMe{
using SafeMathChainlink for uint256;
mapping(address => uint256) public addressToAmountFunded;
address[] public funders;
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");
// 1 gwei < $50
addressToAmountFunded[msg.sender] += msg.value;
funders.push(msg.sender);
// what the eth - > usd conversion rate is
// oracle blockchain , blockchain is determnistic
// centralized orcles are a point of failure
// Decentraliez Oracle Network
// data.chain.link
}
function getVersion() public view returns (uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
return priceFeed.version();
}
function getPrice() public view returns(uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
(,int256 answer,,,) = priceFeed.latestRoundData();
return uint256(answer * 10000000000);
}
function getConversionRate(uint256 ethAmount) public view returns(uint256){
uint256 ethprice = getPrice();
uint256 ethAmountInUsd = (ethprice * ethAmount) / 100000000000000000;
return ethAmountInUsd;
}
modifier onlyOwner{
require(msg.sender == owner,"not owner");
_;
}
function withdraw() payable onlyOwner public {
//only want the contract admin/owner
// require msg.sender = owner
msg.sender.transfer(address(this).balance);
for( uint256 funderIndex = 0; funderIndex < funders.length ; funderIndex++){
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
funders = new address[](0);
}
}