Skip to content

Instantly share code, notes, and snippets.

@hannesroth88
Created September 28, 2022 21:39
Show Gist options
  • Save hannesroth88/24a119188f98342b73cc67e7fabe35d1 to your computer and use it in GitHub Desktop.
Save hannesroth88/24a119188f98342b73cc67e7fabe35d1 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 "./PriceConverter.sol";
contract FundMe{
using PriceConverter for uint256;
uint256 public minimumUsd = 10 * 1e18;
address[] public addressesFunders;
mapping(address => uint256) public addressesToAmountFunded;
function fund() public payable {
require( msg.value.getConversionRate() > minimumUsd, "didn't send enough");
addressesFunders.push(msg.sender);
addressesToAmountFunded[msg.sender] = msg.value;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17; // Hi I'am new to Solidity
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
library PriceConverter {
function getPrice() internal view returns (uint256) {
// Goerli ETH / USD Address
// https://docs.chain.link/docs/ethereum-addresses/
AggregatorV3Interface priceFeed = AggregatorV3Interface(
0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e
);
(, int256 answer, , , ) = priceFeed.latestRoundData();
// ETH/USD rate in 18 digit
return uint256(answer * 10000000000);
}
// 1000000000
function getConversionRate(uint256 ethAmount)
internal
view
returns (uint256)
{
uint256 ethPrice = getPrice();
uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;
// the actual ETH/USD conversion rate, after adjusting the extra 0s.
return ethAmountInUsd;
}
function getVersion() internal view returns(uint256) {
// ETHUSD Price Feed Address = 0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e
AggregatorV3Interface priceFeed = AggregatorV3Interface(
0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e
);
return priceFeed.version();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment