{"id":26469819,"url":"https://github.com/ocdbytes/fundme","last_synced_at":"2025-03-19T17:09:30.051Z","repository":{"id":113749570,"uuid":"449231201","full_name":"ocdbytes/FundMe","owner":"ocdbytes","description":"This is a Solidity Contract in which I can receive etheriums from different accounts and only i have the access to withdraw the tokens and users can chack how many ethers they have spent","archived":false,"fork":false,"pushed_at":"2022-01-18T10:07:19.000Z","size":2586,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-14T10:46:07.917Z","etag":null,"topics":["ethereum","solidity","transaction"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ocdbytes.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-01-18T10:03:41.000Z","updated_at":"2022-02-05T18:31:05.000Z","dependencies_parsed_at":"2023-03-15T11:30:28.810Z","dependency_job_id":null,"html_url":"https://github.com/ocdbytes/FundMe","commit_stats":null,"previous_names":["ocdbytes/fundme"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocdbytes%2FFundMe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocdbytes%2FFundMe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocdbytes%2FFundMe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocdbytes%2FFundMe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ocdbytes","download_url":"https://codeload.github.com/ocdbytes/FundMe/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244470251,"owners_count":20457908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ethereum","solidity","transaction"],"created_at":"2025-03-19T17:09:29.462Z","updated_at":"2025-03-19T17:09:30.046Z","avatar_url":"https://github.com/ocdbytes.png","language":"Solidity","readme":"\u003cimg src=\"Solidity%20-%20Fund%20Me%200e1e08a29d2747ce99475e4679790ff2/main.png\" width=\"100%\"\u003e\u003c/img\u003e\n\n# Solidity - Fund Me\n\nIn this contract we are going to add a functionality to receive and withdraw payment\n\nGet free tokens at\n\n[LINK Token Contracts | Chainlink Documentation](https://docs.chain.link/docs/link-token-contracts/)\n\n## Payable Function\n\nIf we declare our function as payable it means that we can accept payment on that function\n\n```solidity\n// SPDX_License_Identifier: MIT\n\npragma solidity \u003e=0.6.6 \u003c0.9.0;\n\n// Here we will make a contract that will accept payment\ncontract FundMe{\n    function fund() public payable {\n\n    }\n}\n```\n\nAfter deployment\n\n![Screenshot 2022-01-17 at 11.08.47 PM.png](Solidity%20-%20Fund%20Me%200e1e08a29d2747ce99475e4679790ff2/Screenshot_2022-01-17_at_11.08.47_PM.png)\n\nThis Red button means it is used for transaction\n\n### Keeping track of the payments done by a particular address →\n\n```solidity\n// SPDX_License_Identifier: MIT\n\npragma solidity \u003e=0.6.6 \u003c0.9.0;\n\n// Here we will make a contract that will accept payment\ncontract FundMe{\n\n    // we made a mapping to get the amount sent to us by a particular address\n    mapping(address =\u003e uint256) public addressToAmountFunded;\n\n    // if we declare our function as payable it means that we can accept it as payment\n    function fund() public payable {\n        // This code adds amount sent by address in the mapping\n        addressToAmountFunded[msg.sender] += msg.value;\n    }\n}\n```\n\n![Screenshot 2022-01-17 at 11.17.01 PM.png](Solidity%20-%20Fund%20Me%200e1e08a29d2747ce99475e4679790ff2/Screenshot_2022-01-17_at_11.17.01_PM.png)\n\n![Screenshot 2022-01-17 at 11.20.52 PM.png](Solidity%20-%20Fund%20Me%200e1e08a29d2747ce99475e4679790ff2/Screenshot_2022-01-17_at_11.20.52_PM.png)\n\n### In order to make a minimum limit for a transaction we need the latest price for Etherium so we will get data from (we can’t use any single owned api to get price because of security issue or ruining the concept of decentralisation)\n\n### We can check the prices at →\n\n[Decentralized Price Reference Data | Chainlink](https://data.chain.link/)\n\n### We can get live price Chainlink API at →\n\n[Data Feeds Contract Addresses | Chainlink Documentation](https://docs.chain.link/docs/reference-contracts/)\n\nAPI Code is available in the documentation only and a link is given there to open it directly in Remix IDE\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\n\nimport \"@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol\";\n\ncontract PriceConsumerV3 {\n\n    AggregatorV3Interface internal priceFeed;\n\n    /**\n     * Network: Kovan\n     * Aggregator: ETH/USD\n     * Address: 0x9326BFA02ADD2366b30bacB125260Af641031331\n     */\n    constructor() {\n        priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331);\n    }\n\n    /**\n     * Returns the latest price\n     */\n    function getLatestPrice() public view returns (int) {\n        (\n            uint80 roundID,\n            int price,\n            uint startedAt,\n            uint timeStamp,\n            uint80 answeredInRound\n        ) = priceFeed.latestRoundData();\n        return price;\n    }\n}\n```\n\nAfter Deploying →\n\n![Screenshot 2022-01-17 at 11.51.43 PM.png](Solidity%20-%20Fund%20Me%200e1e08a29d2747ce99475e4679790ff2/Screenshot_2022-01-17_at_11.51.43_PM.png)\n\n\\*\\*This must be deployed on Web3 only because nodes are available in web3 not in a virtual environment\n\n### ABI (Application Binary Interface) →\n\nABI tells solidity and other languages how it can interact with other contracts\n\nIf we want to interact with already deployed contract then we surely need ABI\n\n- Interfaces compile down to ABI\n\n### Data feed Keys are available at →\n\n[Ethereum Data Feeds | Chainlink Documentation](https://docs.chain.link/docs/ethereum-addresses/)\n\n```solidity\n// SPDX-License-Identifier: MIT\n\npragma solidity \u003e=0.6.6 \u003c0.9.0;\n\n// importing the chainlink code for getting the price feed\n// we can also copy the original code but the import statement will also work fine\nimport \"@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol\";\n\n// Here we will make a contract that will accept payment\ncontract FundMe{\n\n    // we made a mapping to get the amount sent to us by a particular address\n    mapping(address =\u003e uint256) public addressToAmountFunded;\n\n    // if we declare our function as payable it means that we can accept it as payment\n    function fund() public payable {\n        // This code adds amount sent by address in the mapping\n        addressToAmountFunded[msg.sender] += msg.value;\n    }\n\n    function getVersion() public view returns (uint256){\n        // defining a AggregatorV3Interface instance here\n        // The key provided is the chainlink price feed key that is avialable in chainlink documentation\n        AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);\n        return priceFeed.version();\n    }\n\n}\n```\n\nAfter Deployment →\n\n![Screenshot 2022-01-18 at 1.54.22 PM.png](Solidity%20-%20Fund%20Me%200e1e08a29d2747ce99475e4679790ff2/Screenshot_2022-01-18_at_1.54.22_PM.png)\n\nWe can see the [getVersion] Function which is equal to the [version] function in [AggregatorV3Interface.sol]\n\n### Add minimum amount \u0026 Revert transaction if condition not met\n\n### Adding a withdraw method to withdraw all the funds that we have deposited\n\n```solidity\n// SPDX-License-Identifier: MIT\n\npragma solidity \u003e=0.6.6 \u003c0.9.0;\n\n// importing the chainlink code for getting the price feed\n// we can also copy the original code but the import statement will also work fine\nimport \"@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol\";\n// using safe math to check for any integer overflows or underflows\nimport \"@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol\";\n\n// Here we will make a contract that will accept payment\ncontract FundMe{\n\n    using SafeMathChainlink for uint256;\n\n    // we made a mapping to get the amount sent to us by a particular address\n    mapping(address =\u003e uint256) public addressToAmountFunded;\n\n    // if we declare our function as payable it means that we can accept it as payment\n    function fund() public payable {\n        // $50\n        uint256 minimumUSD = 50 * (10**18); // WEI\n        require(getConversionRate(msg.value) \u003e= minimumUSD, \"You need to spend more eth\"); // This will check for the condition here and revert if its not true\n        // This code adds amount sent by address in the mapping\n        addressToAmountFunded[msg.sender] += msg.value;\n    }\n\n    function getVersion() public view returns (uint256){\n        // defining a AggregatorV3Interface instance here\n        // The key provided is the chainlink price feed key that is avialable in chainlink documentation\n        AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);\n        return priceFeed.version();\n    }\n\n    // This will return the latest price of etherium\n    function getPrice() public view returns(uint256){\n        AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);\n        (uint80 roundId,int256 answer,uint256 startedAt,uint256 updatedAt,uint80 answeredInRound) = priceFeed.latestRoundData();\n        return uint256(answer * 10000000000);\n    }\n\n    // 1 Eth = 1000000000 GWEI = 10^9 GWEI\n    function getConversionRate(uint256 ethAmount) public view returns (uint256){\n        uint256 ethPrice = getPrice();\n        uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;\n        return ethAmountInUsd;\n        // This will give us the value in USD = ethAmountInUsd * 10^-10 * 1 GWEI\n    }\n\n    // Withdrawing the amount sent to the contract\n    function withdraw() payable public{\n        // this keyword is same as python\n        msg.sender.transfer(address(this).balance);\n    }\n}\n```\n\n### If we want a functionality if only owner can withdraw the funds collected\n\n(Constructors)\n\n```solidity\n// SPDX-License-Identifier: MIT\n\npragma solidity \u003e=0.6.6 \u003c0.9.0;\n\n// importing the chainlink code for getting the price feed\n// we can also copy the original code but the import statement will also work fine\nimport \"@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol\";\n// using safe math to check for any integer overflows or underflows\nimport \"@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol\";\n\n// Here we will make a contract that will accept payment\ncontract FundMe{\n\n    using SafeMathChainlink for uint256;\n\n    // we made a mapping to get the amount sent to us by a particular address\n    mapping(address =\u003e uint256) public addressToAmountFunded;\n    address public owner;\n\n    // Constructor\n    constructor() public {\n        owner = msg.sender;\n    }\n\n    // if we declare our function as payable it means that we can accept it as payment\n    function fund() public payable {\n        // $50\n        uint256 minimumUSD = 50 * (10**18); // WEI\n        require(getConversionRate(msg.value) \u003e= minimumUSD, \"You need to spend more eth\"); // This will check for the condition here and revert if its not true\n        // This code adds amount sent by address in the mapping\n        addressToAmountFunded[msg.sender] += msg.value;\n    }\n\n    function getVersion() public view returns (uint256){\n        // defining a AggregatorV3Interface instance here\n        // The key provided is the chainlink price feed key that is avialable in chainlink documentation\n        AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);\n        return priceFeed.version();\n    }\n\n    // This will return the latest price of etherium\n    function getPrice() public view returns(uint256){\n        AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);\n        // values between the commas will be ignored\n        (,int256 answer,,,) = priceFeed.latestRoundData();\n        return uint256(answer * 10000000000);\n    }\n\n    // 1 Eth = 1000000000 GWEI = 10^9 GWEI\n    function getConversionRate(uint256 ethAmount) public view returns (uint256){\n        uint256 ethPrice = getPrice();\n        uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;\n        return ethAmountInUsd;\n        // This will give us the value in USD = ethAmountInUsd * 10^-10 * 1 GWEI\n    }\n\n    // Withdrawing the amount sent to the contract\n    function withdraw() payable public{\n        require(msg.sender == owner, \"You are not allowed to withdraw\"); //chacking if the owner is withdrawing or someone else\n        // this keyword is same as python\n        msg.sender.transfer(address(this).balance);\n    }\n}\n```\n\n## Modifiers\n\nModifiers allow us to change the behaviour of a function in a declarative way. we can customise it according to our interest\n\n\\*\\* We will add only owner property using modifiers\n\n```solidity\n// SPDX-License-Identifier: MIT\n\npragma solidity \u003e=0.6.6 \u003c0.9.0;\n\n// importing the chainlink code for getting the price feed\n// we can also copy the original code but the import statement will also work fine\nimport \"@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol\";\n// using safe math to check for any integer overflows or underflows\nimport \"@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol\";\n\n// Here we will make a contract that will accept payment\ncontract FundMe{\n\n    using SafeMathChainlink for uint256;\n\n    // we made a mapping to get the amount sent to us by a particular address\n    mapping(address =\u003e uint256) public addressToAmountFunded;\n    address public owner;\n\n    // Constructor\n    constructor() public {\n        owner = msg.sender;\n    }\n\n    // if we declare our function as payable it means that we can accept it as payment\n    function fund() public payable {\n        // $50\n        uint256 minimumUSD = 50 * (10**18); // WEI\n        require(getConversionRate(msg.value) \u003e= minimumUSD, \"You need to spend more eth\"); // This will check for the condition here and revert if its not true\n        // This code adds amount sent by address in the mapping\n        addressToAmountFunded[msg.sender] += msg.value;\n    }\n\n    function getVersion() public view returns (uint256){\n        // defining a AggregatorV3Interface instance here\n        // The key provided is the chainlink price feed key that is avialable in chainlink documentation\n        AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);\n        return priceFeed.version();\n    }\n\n    // This will return the latest price of etherium\n    function getPrice() public view returns(uint256){\n        AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);\n        // values between the commas will be ignored\n        (,int256 answer,,,) = priceFeed.latestRoundData();\n        return uint256(answer * 10000000000);\n    }\n\n    // 1 Eth = 1000000000 GWEI = 10^9 GWEI\n    function getConversionRate(uint256 ethAmount) public view returns (uint256){\n        uint256 ethPrice = getPrice();\n        uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;\n        return ethAmountInUsd;\n        // This will give us the value in USD = ethAmountInUsd * 10^-10 * 1 GWEI\n    }\n\n    // Adding modifier to check if a owner is accessing a particular function or not\n    modifier onlyOwner{\n        require(msg.sender == owner, \"You are not allowed to withdraw\");\n        _;\n    }\n\n    // Withdrawing the amount sent to the contract\n    function withdraw() payable onlyOwner public{\n        msg.sender.transfer(address(this).balance);\n    }\n}\n```\n\n## Resetting →\n\n```solidity\n// SPDX-License-Identifier: MIT\n\npragma solidity \u003e=0.6.6 \u003c0.9.0;\n\n// importing the chainlink code for getting the price feed\n// we can also copy the original code but the import statement will also work fine\nimport \"@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol\";\n// using safe math to check for any integer overflows or underflows\nimport \"@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol\";\n\n// Here we will make a contract that will accept payment\ncontract FundMe{\n\n    using SafeMathChainlink for uint256;\n\n    // we made a mapping to get the amount sent to us by a particular address\n    mapping(address =\u003e uint256) public addressToAmountFunded;\n    address[] public funders; // array to keep track of all addresses\n    address public owner;\n\n    // Constructor\n    constructor() public {\n        owner = msg.sender;\n    }\n\n    // if we declare our function as payable it means that we can accept it as payment\n    function fund() public payable {\n        // $50\n        uint256 minimumUSD = 50 * (10**18); // WEI\n        require(getConversionRate(msg.value) \u003e= minimumUSD, \"You need to spend more eth\"); // This will check for the condition here and revert if its not true\n        // This code adds amount sent by address in the mapping\n        addressToAmountFunded[msg.sender] += msg.value;\n        // pushing address to funders array\n        funders.push(msg.sender);\n    }\n\n    function getVersion() public view returns (uint256){\n        // defining a AggregatorV3Interface instance here\n        // The key provided is the chainlink price feed key that is avialable in chainlink documentation\n        AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);\n        return priceFeed.version();\n    }\n\n    // This will return the latest price of etherium\n    function getPrice() public view returns(uint256){\n        AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);\n        // values between the commas will be ignored\n        (,int256 answer,,,) = priceFeed.latestRoundData();\n        return uint256(answer * 10000000000);\n        // returns usd value in 18 decimals\n    }\n\n    // 1 Eth = 1000000000 GWEI = 10^9 GWEI\n    function getConversionRate(uint256 ethAmount) public view returns (uint256){\n        uint256 ethPrice = getPrice();\n        uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;\n        return ethAmountInUsd;\n        // This will give us the value in USD = ethAmountInUsd * 10^-10 * 1 GWEI\n    }\n\n    // Adding modifier to check if a owner is accessing a particular function or not\n    modifier onlyOwner{\n        require(msg.sender == owner, \"You are not allowed to withdraw\");\n        _;\n    }\n\n    // Withdrawing the amount sent to the contract\n    function withdraw() payable onlyOwner public{\n        msg.sender.transfer(address(this).balance);\n        // for loop to reset the amount when all tokens withdrawn\n        for (uint256 fundersIndex = 0; funderIndex \u003c funders.length; fundersIndex++){\n            address funder = funders[fundersIndex];\n            addressToAmountFunded[funder] = 0;\n        }\n        funders = new address[]; // resetting the array\n    }\n}\n```\n\n### Our Full Fund Me Application is now complete\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focdbytes%2Ffundme","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Focdbytes%2Ffundme","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focdbytes%2Ffundme/lists"}