-
FundMe-RemixIDE: Failing to FUND after having deployed the contract. Please do note that I am taking into account the current price of ETH in USD. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 6 replies
-
send a snippet of your source code... |
Beta Was this translation helpful? Give feedback.
-
`pragma solidity ^0.8.13; import "./PriceConverter.sol"; contract FundMe {
}` |
Beta Was this translation helpful? Give feedback.
-
I kept going with the video and finished the remix part, the code I am going to send, is the same I send above but with some gas optimization (constant, immutable keywords, use of fallbacks,...) nothing that changes the logic of the code, it just reduces the gas spent at contract deployment. import "./PriceConverter.sol"; error NotOwner(); contract FundMe {
}` |
Beta Was this translation helpful? Give feedback.
-
// Get Funds from users
// Witrhdraw funds
// Set a minimum funding value in USD
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "./PriceConverter.sol";
error NotOwner();
contract FundMe {
using PriceConverter for uint256; // Attaching our Library to uint256
uint256 public constant minimumUSD = 50 * 1e18;
address public immutable owner;
constructor() {
owner = msg.sender;
}
address[] public funders;
mapping(address => uint256) public addressToAmountFunded;
function fund() public payable {
// Want to be able to set a minimum fund amount in USD
// How do we send ETH to this contract?
require(msg.value.getConversionRate() >= minimumUSD, "Didn't send enough"); // 1 ETH = 1e18 = 1 * 10 ** 18 = 1000000000000000000 Wei
funders.push(msg.sender);
addressToAmountFunded[msg.sender] += msg.value;
}
function withdraw() public onlyOwner {
for (uint funderIndex = 0; funderIndex < funders.length; funderIndex++) {
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
// reset the array
funders = new address[](0);
// actually withdraw the funds
(bool succ,) = payable(msg.sender).call{value: address(this).balance}("");
require(succ, "Call failed");
}
modifier onlyOwner() {
if(msg.sender != owner)
revert NotOwner();
_;
}
// What if someone decides to fund the contract without using the Fund() function
receive() external payable {
fund();
}
fallback() external payable {
fund();
}
} |
Beta Was this translation helpful? Give feedback.
-
@joe17ar Which price feed address are you using? |
Beta Was this translation helpful? Give feedback.
-
@alymurtazamemon I just checked and I used that of the mainnet instead of that of goerli now it works just fine! Thanks for your help! |
Beta Was this translation helpful? Give feedback.
@alymurtazamemon I just checked and I used that of the mainnet instead of that of goerli now it works just fine! Thanks for your help!