Error:Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? #756
Answered
by
0xSanyam
AwaisTahseencode
asked this question in
Q&A
-
//It compiled perfectly
//I tested this both with rikeby and also with kovan but error remains the same i couldn't figured out the error , kindly help me out
//SPDX-License-Identifier:MIT
pragma solidity ^0.8;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract FundMe{
uint256 minAmount=50*1e18;
function deposit ()public payable {
require(getConversionRate(msg.value)>=minAmount,"Don't have enough amount");
}
function getPrice() public view returns(uint256){
AggregatorV3Interface avi=AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
(,int256 price,,,)=avi.latestRoundData();
return uint256(price*1e18);
}
function getConversionRate(uint256 ETH) public view returns(uint256){
uint256 ETHPrice=getPrice();
return ((ETHPrice*ETH)/1e18);
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
0xSanyam
Jul 5, 2022
Replies: 2 comments 3 replies
-
@AwaisTahseencode make the minAmount public so that other functions can use it and you have to multiply the 1e18 part with 50. When returning price multiply it with 1e10 as 8 decimals are already there (making it a total of 18 decimals) uint256 public minAmount=50 * 1e18;
// rest of the code
return uint256(price * 1e10); Also, you may/should refer this |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
alymurtazamemon
-
This is a generic error for not meeting a require/if statement. Some times its thrown if the your trying to call a function that will fail due to not having ETH. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@AwaisTahseencode make the minAmount public so that other functions can use it and you have to multiply the 1e18 part with 50. When returning price multiply it with 1e10 as 8 decimals are already there (making it a total of 18 decimals)
Also, you may/should refer this