Last active
June 22, 2022 03:40
-
-
Save bertil291utn/eb0d76e4764b2c98ded133b4c492f152 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.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
This file contains 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-Identifer: MIT | |
pragma solidity ^0.8.4; | |
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; | |
import "./PriceConverter.sol"; | |
error noOwner(); | |
contract FundMe{ | |
using PriceConverter for uint256; | |
mapping(address=>uint256) public addressFundedAmount; | |
address [] investorsAddress; | |
address public immutable i_owner; | |
uint256 public minUSD; | |
// uint256 public constant MIN_USD=50*10e18 // for a constant variable | |
constructor(){ | |
i_owner=msg.sender; | |
} | |
function fund() public payable{ | |
require(msg.value.convert()>= minUSD,string(abi.encodePacked("You need to get minimum amount of ",minUSD," USD"))); | |
addressFundedAmount[msg.sender]+= msg.value; | |
investorsAddress.push(msg.sender); | |
} | |
modifier onlyOwner{ | |
require(msg.sender==i_owner,"Only owners"); | |
_; | |
} | |
modifier admin(){ | |
if(msg.sender!=i_owner){ | |
revert noOwner(); | |
} | |
_; | |
} | |
function withdraw() payable onlyOwner public { | |
resetBalances(); | |
(bool callSuccess,)=payable(msg.sender).call{value:address(this).balance}(""); | |
require(callSuccess, "Couldn't send money"); | |
} | |
function setMinUSD(uint256 _minUSDValue) onlyOwner public { | |
minUSD=_minUSDValue; | |
} | |
receive() external payable{ | |
fund(); | |
} | |
fallback() external payable{ | |
fund(); | |
} | |
//private | |
function resetBalances() private { | |
for (uint i=0; i< investorsAddress.length ; i++){ | |
delete addressFundedAmount[investorsAddress[i]]; | |
delete investorsAddress[i]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment