-
I'm able to fund the contract with the correct calculated value in Wei, but when I go to withdraw the funds back out. The function takes some time to think, then gives me a Gas Estimation Failed: Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? I thought this was an address issue for funds only, when I enter the same amount of Wei back in the Value field, it still gives me the error for withdraw. // SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "./PriceConverter.sol";
contract FundMe {
using PriceConverter for uint256;
uint256 public minimumUsd = 50 * 1e18; // Divide x amount of USD by current price of ETH
address[] public funders;
mapping(address => uint256) public addressToAmountFunded;
address public owner;
constructor() {
owner = msg.sender;
}
function fund() public payable {
// Want to be able to set a minimum fund amount in USD
// 1. How do we send eth to this contract?
// To get the value of how much someone is sending msg.value
// 1e18 = 1 * 10 ** 18 == 1000000000000000000
require(msg.value.getConversionRate() >= minimumUsd, "Didn't send enough!");
funders.push(msg.sender);
addressToAmountFunded[msg.sender] = msg.value;
// Reverting undos any action before and sends any remaining gas back
}
function withdraw() public onlyOwner {
// for(/* starting index, ending index, step amount */)
// 0, 10, 2
for(uint256 funderIndex = 0; funderIndex < funders.length; funderIndex = funderIndex++){
// code
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
// resetting array
funders = new address[](0);
(bool callSuccess,) = payable(msg.sender).call{value: address(this).balance}("");
require(callSuccess, "Call failed");
}
modifier onlyOwner {
require(msg.sender == owner, "Sender is not owner");
_;
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Also get this error: Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? |
Beta Was this translation helpful? Give feedback.
-
I didn't include "payable" in my withdraw function. Fixed it! |
Beta Was this translation helpful? Give feedback.
I didn't include "payable" in my withdraw function. Fixed it!