Created
January 16, 2025 13:42
-
-
Save Charlie-pang-sys/470b880da40bfbf342835bb2b33b7b54 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.26+commit.8a97fa7a.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: MIT | |
| pragma solidity ^0.8.20; | |
| import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol"; | |
| contract FundMe{ | |
| // 1、创建一个收款函数 | |
| // 2、记录投资人并且查看 | |
| // 3、在锁定期内,没有达到目标值,投资人在锁定期以后退款 | |
| mapping(address=>uint256) public fundersToAmount; | |
| uint256 MINIMUM_VALUE = 100 * 10 ** 18; //USD | |
| AggregatorV3Interface internal dataFeed; | |
| constructor(){ | |
| dataFeed = AggregatorV3Interface(0x694AA1769357215DE4FAC081bf1f309aDC325306); | |
| } | |
| function fund() external payable { | |
| require(convertEthToUsd(msg.value) >= MINIMUM_VALUE,"Send more ETH"); | |
| fundersToAmount[msg.sender] = msg.value; | |
| } | |
| /** | |
| * Returns the latest answer. | |
| */ | |
| function getChainlinkDataFeedLatestAnswer() public view returns (int) { | |
| // prettier-ignore | |
| ( | |
| /* uint80 roundID */, | |
| int answer, | |
| /*uint startedAt*/, | |
| /*uint timeStamp*/, | |
| /*uint80 answeredInRound*/ | |
| ) = dataFeed.latestRoundData(); | |
| return answer; | |
| } | |
| function convertEthToUsd(uint256 ethAmount) internal view returns(uint256){ | |
| uint256 price = uint256(getChainlinkDataFeedLatestAnswer()); | |
| return ethAmount * price /(10 **8); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment