0
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; // import eth/usd price feed contract

contract FundMe {

    mapping (address => uint256) public addressToAmountFunded;

    function fund() public payable {
        uint256 minimumUSD = 50 * 10 ** 18;
        require(getConversionRate(msg.value) >= minimumUSD, "Minimum requiremens are not met.");
        addressToAmountFunded[msg.sender] += msg.value;
    }

    function getVersion() public view returns(uint256) {
        AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
        return priceFeed.version(); // gets version of the AggregatorV3Interface
    }

    // what the ETH => USD converstion rate is
    function getPrice() public view returns(uint256) {
        AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
        (,int256 answer,,,) = priceFeed.latestRoundData();
        return uint256(answer);
    }

    function getConversionRate(uint256 ethAmount) public view returns(uint256) {
        uint256 ethPrice = getPrice();
        uint256 ethAmountInUSD = (ethAmount * ethPrice) / 1000000000000000000;
        return ethAmountInUSD;
    }

    function withdraw() payable public {
       msg.sender.transfer(address(this).balance);
    }
}
1
  • So I am trying to compile a withdraw function that would withdraw the whole balance back to the sender after we fund the contract using the fund () function; When i compile i get: TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address". What can i do to fix that?
    – PinkyZane
    Dec 1, 2021 at 19:42

1 Answer 1

0

The address must be of type payable to use either send or transfer, if you change it to look like this it will compile:

 function withdraw() payable public {
       payable(msg.sender).transfer(address(this).balance);
    }

Not the answer you're looking for? Browse other questions tagged or ask your own question.