Skip to content

Instantly share code, notes, and snippets.

@hannesroth88
Created September 28, 2022 13:49
Show Gist options
  • Save hannesroth88/4f83163896f51446ea1bae401b73fb72 to your computer and use it in GitHub Desktop.
Save hannesroth88/4f83163896f51446ea1bae401b73fb72 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.8+commit.dddeac2f.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17; // Hi I'am new to Solidity
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract FundMe{
uint256 public minimumUsd = 10 * 1e18;
address[] public addressesFunders;
mapping(address => uint256) public addressesToAmountFunded;
AggregatorV3Interface priceFeed;
constructor() {
priceFeed = AggregatorV3Interface(0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e);
}
function fund() public payable {
require( getConversionRate(msg.value) > minimumUsd, "didn't send enough");
addressesFunders.push(msg.sender);
addressesToAmountFunded[msg.sender] = msg.value;
}
function getPrice() public view returns(uint256) {
(,int price,,,) = priceFeed.latestRoundData();
// ETH in terms of USD
// price feed has 8 decimals
return uint256(price * 1e10);
}
function getConversionRate(uint256 _valueSent) public view returns (uint256){
uint256 priceEthInUsd = getPrice();
return (priceEthInUsd * _valueSent / 1e18);
}
function getVersion() public view returns(uint256) {
// ETHUSD Price Feed Address = 0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e
return priceFeed.version();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment