[英]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). Gas estimation failed Close Gas estimation errored 并显示以下消息(见下文)。 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.基本上,当我在部署时在我的合同中传递任何 Wei、gwei 或以太币时,我会收到此错误,否则它会被部署。
While you deploy your contract, your constructor
function is called, and it is not marked as payable.当你部署你的合约时,你的
constructor
function 被调用,它没有被标记为 payable。
constructor() payable {
owner = msg.sender;
}
Make it payable and you are good付钱,你就很好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.