Lesson 8: Error: Transaction reverted: function selector was not recognized and there's no fallback function (at MockV3Aggregator.<unrecognized-selector>) #5431
-
I'm facing this error when I call the fund function from the frontend. I know people have posted on this particular error, I followed their corrections but it was to no avail, and I noticed my error was a little different. While others were coming from the FundMe contract :
This is the error that showed on the browers:
This is the fundme contract: // SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "./PriceConverter.sol";
error FundMe__notOwner();
/**
* @title A contract for funding diseased people
* @author Bishop Akin-Thomas
* @notice This contract is to demo a sample funding contract. #It's not real
* @dev This implements price feeds as our libary
*/
contract FundMe {
using PriceConverter for uint;
uint public constant MINIMUM_USD = 50 * 1e18;
address private immutable owner;
address[] private funders;
mapping(address => uint) private amountToFunders;
AggregatorV3Interface private priceFeed;
modifier isPriceEnough() {
//set a minimum fund amount in USD
require(
msg.value.getConversionRate(priceFeed) >= MINIMUM_USD,
"Not enough ether"
);
_;
}
modifier isOwner() {
// require(owner == msg.sender, "Not the owner");
if (owner != msg.sender) {
revert FundMe__notOwner();
}
_;
}
constructor(address priceFeedAddress) {
owner = msg.sender;
priceFeed = AggregatorV3Interface(priceFeedAddress);
}
// receive() external payable {}
// fallback() external payable {}
receive() external payable {
fund();
}
// fallback() external payable {
// fund();
// }
fallback() external payable {
if (msg.value > 100) {
fund();
}
}
function fund() public payable isPriceEnough {
funders.push(msg.sender);
amountToFunders[msg.sender] += msg.value; //add address that funded
}
function withdraw() public isOwner {
for (uint i = 0; i < funders.length; i++) {
address funder = funders[i];
amountToFunders[funder] = 0;
}
//reset the array
funders = new address[](0);
/*Withdraw the funded money*/
/*transfer method*/
// payable(msg.sender).transfer(address(this).balance);
/*send method*/
// bool sendSuccess = payable(msg.sender).send(address(this).balance);
// require(sendSuccess, "Sending failed");
//call method
(bool callSuccess, ) = payable(msg.sender).call{
value: address(this).balance
}("");
require(callSuccess, "Call failed");
}
function getOwner() public view returns (address) {
return owner;
}
function getFunder(uint256 index) public view returns (address) {
return funders[index];
}
function getAmountToFunders(address funder) public view returns (uint256) {
return amountToFunders[funder];
}
function getPriceFeed() public view returns (AggregatorV3Interface) {
return priceFeed;
}
} And this is the fund function of the index.js in the frontend: async function fund() {
const ethAmount = '77'
console.log(`Funding with ${ethAmount}`)
if (typeof window.ethereum !== "undefined") {
//provider | blockchain to connect to
const provider = new ethers.providers.Web3Provider(window.ethereum)
//signer | wallet with some gas to use
const signer = provider.getSigner()
console.log(signer)
//contract to interact with
//^ABI && Address
const contracts = new ethers.Contract(contractAddress,abi,signer)
const txResponse = new contracts.fund({value: ethers.utils.parseEther(ethAmount)})
}
} I'm really lost please can someone help me figure out what's wrong. Thank you in anticipation |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@AKIN-THOMAS Check out this discussion #315 |
Beta Was this translation helpful? Give feedback.
@AKIN-THOMAS Check out this discussion #315