Skip to content

Create 32 #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions 32
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// SPDX-License-Identifier: MIT

// Smart contract that lets anyone deposit ETH into the contract
// Only the owner of the contract can withdraw the ETH
pragma solidity >=0.6.6 <0.9.0;

import "./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 minimunUSD = 50 * 10 ** 18;
require(getConversionRate(msg.value) >= minimunUSD, "You need to spend more ETH!");
addressToAmountFunded[msg.sender] += msg.value;
funders.push(msg.sender);
}

function getVersion() public view returns(uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
return priceFeed.version();
}

function getPrice() public view returns(uint256){
AggregatorV3Interface priceFeed=AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);

// (uint80 roundId,
// int256 answer,
// uint256 startedAt,
// uint256 updatedAt,
// uint80 answeredInRound ) = priceFeed.latestRoundData();

(,int256 answer,,,) = priceFeed.latestRoundData();
return uint256(answer * 10000000000);
}

function getConversionRate(uint256 ethAmount) public view returns(uint256){
uint256 ethPrice = getPrice();
uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;
return ethAmountInUsd;
}

// Modifier that help us apply some behaviors on our withdraw function for only the admin/owner to withdraw
modifier OnlyOwner {
require(msg.sender == owner, "Oups...Only the Admin or the Owner of this contract can withdraw!!!");
_;
}
function withdraw() payable OnlyOwner public {
// Only the contract admin/owner can withdraw from this account
//require(msg.sender == owner,"Oups...Only the Admin or the Owner of this contract can withdraw!!!");
msg.sender.transfer(address(this).balance);

// resetting the balance to Zero by looping through all the senders and set the total amount to Zero
for (uint256 funderIndex=0;funderIndex < funders.length;funderIndex++){
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
funders = new address[](0);
}
// Get the balance of tehe current account
function getBalance() public view returns(uint256) {
return address(this).balance;
}
}