'I am trying to write a simple smart contract in remix ide and getting encountered by a generic error again and again. Below is my code and error
Code:-
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract FundMe{
mapping(address => uint256) public addressToAmountFunded;
address public owner;
constructor() public {
owner = msg.sender;
}
function fund() public payable {
uint256 minimumUSD = 50 * 10 ** 18;
require(getConversionRate(msg.value) >= minimumUSD, "You need to spend more ETH!");
addressToAmountFunded[msg.sender] += msg.value;
}
function getVersion() public view returns (uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
return priceFeed.version();
}
function getPrice() public view returns(uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
(,int256 answer,,,) = priceFeed.latestRoundData();
// ETH/USD rate in 18 digit
return uint256(answer * 10000000000);
}
function getConversionRate(uint256 ethAmount) public view returns (uint256){
uint256 ethPrice = getPrice();
uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;
// the actual ETH/USD conversation rate, after adjusting the extra 0s.
return ethAmountInUsd;
}
function withdraw() payable public {
require(msg.sender == owner);
payable(msg.sender).transfer(address(this).balance);
}
}
Error:-
Gas estimation failed Close Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? execution reverted
Basically when I am passing any Wei,gwei, or ether in my contract while deploying then I am getting this error otherwise it gets deployed.
Solution 1:[1]
While you deploy your contract, your constructor function is called, and it is not marked as payable.
constructor() payable {
owner = msg.sender;
}
Make it payable and you are good
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | keser |
