full-blockchain-solidity-course-js
full-blockchain-solidity-course-js copied to clipboard
I keep getting error when I call fund function
trafficstars
Lesson
Lesson 4
Could you please leave a link to the timestamp in the video where this error occurs? (You can right click a video and "copy video URL at current time")
https://youtu.be/gyMwXuJrbJQ?t=17832
Operating System
macOS (Apple Silicon)
Describe the bug
I keep getting error when I call fund function

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15; // solidity 0.8.15
import "./PriceConverter.sol";
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "hardhat/console.sol";
// get funds from users
// wthdraw funds
// set a minimum amount of funds value in USD
// 1e18 == 10^18 == 1 ether
error NotOwner();
contract FundMe {
using PriceConverter for uint256;
uint256 public constant MINIMUM_USD = 1 * 1e18;
mapping(address => uint256) public addressToAmountFunded;
address[] public funders;
address public immutable i_owner;
constructor() {
i_owner = msg.sender;
}
function fund() public payable {
console.log(msg.value.getConversionRate());
require(
msg.value.getConversionRate() >= MINIMUM_USD,
"You need to spend more ETH!"
);
addressToAmountFunded[msg.sender] += msg.value;
funders.push(msg.sender);
}
function withdraw() public onlyOwner {
for (
uint256 funderIndex = 0;
funderIndex < funders.length;
funderIndex++
) {
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
funders = new address[](0);
// call
(bool callSuccess, ) = payable(msg.sender).call{
value: address(this).balance
}("");
console.log("callSuccess:", callSuccess);
require(callSuccess, "Call failed");
}
modifier onlyOwner() {
if (msg.sender != i_owner) {
revert NotOwner();
}
_;
}
receive() external payable {
fund();
}
fallback() external payable {
fund();
}
}
Its just remix telling you that the transaction is likely to fail, which I think is because you didn't send any ETH along when trying to use the fund(). Add an arbitrary value of ETH, say 0.1ETH with the transaction.