Created
December 14, 2023 16:57
-
-
Save Scofield-Idehen/e8322fafc9143b26219353a2f5fb65a1 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.22+commit.4fc1097e.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-Identifier: MIT | |
pragma solidity ^0.8.18; | |
import {newfund} from "./test.sol"; | |
contract fundme{ | |
using newfund for uint; | |
address public owner; | |
uint minimunUsd = 5e18; | |
address[] public funders; | |
mapping(address funder => uint amountfunded) public valueofthefund; | |
constructor(){ | |
owner = msg.sender; | |
} | |
//for a Tx to work it must add payable | |
function fund () public payable { | |
//msg.value.getconversion(); | |
//the require checks for the sender of the value to meet a check | |
//require (getconversion(msg.value) > minimunUsd, "Not enough ETH!!!"); | |
require (msg.value.getconversion() <= minimunUsd); | |
funders.push(msg.sender); | |
valueofthefund[msg.sender] += msg.value; | |
} | |
function withdraw () public onlyowner { | |
for (uint funderindex = 0; funderindex < funders.length; funderindex++){ | |
address funder = funders[funderindex]; | |
valueofthefund[funder] = 0; | |
} | |
funders = new address [] (0); | |
// transfer using paybale since we are transfering to another address | |
payable (msg.sender).transfer(address(this).balance); | |
//send | |
bool sendSucess = payable (msg.sender).send(address(this).balance); | |
require (sendSucess, "Failed to send transaction!!!"); | |
//call | |
(bool success, ) = payable (msg.sender).call{value: address(this).balance}(""); | |
require (success, "call failed!!!"); | |
} | |
modifier onlyowner(){ | |
// you can put the _; above the require or below to show which function should be run first!! | |
require (msg.sender == owner, "Must be the owner!!!"); | |
_; | |
} | |
} |
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-Identifier: MIT | |
pragma solidity ^0.8.18; | |
import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; | |
library newfund{ | |
function getUSD() internal view returns (uint) { | |
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x694AA1769357215DE4FAC081bf1f309aDC325306); | |
(,int256 price,,,) = priceFeed.latestRoundData(); | |
return uint (price *1e18); | |
//0x694AA1769357215DE4FAC081bf1f309aDC325306 | |
} | |
function getconversion (uint ethamount) internal view returns (uint) { | |
uint iniprice = getUSD(); | |
uint ethamountUSD = (iniprice * ethamount) /1e18; | |
return ethamountUSD; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment