简体   繁体   English

我试图在 remix ide 中编写一个简单的智能合约,并一次又一次地遇到一般错误。 下面是我的代码和错误

[英]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.

相关问题 我正在尝试起草一份智能合约,混音 IDE 自动完成无法正常工作。 过去有人经历过同样的事情吗? - I am trying to draft a smart contract, the remix IDE auto complete is not working. Anyone experienced the same in the past? 我试图测试这种流动性智能合约代码,但如果显示错误。 流动性类似于ocaml,tezos的智能合约语言。 - I am trying to test this liquidity smart contract code but if shows error. Liquidity is similar to ocaml, tezos's smart contract language. 将智能合约从混音部署到 azure 区块链的问题 - 错误 - Issue deploying smart contract from remix to azure blockchain - error 尝试在松露快递盒中使用智能合约写入数据时出现无效地址错误 - Getting an Invalid Address error when trying to write data with smart contract in truffle express box "在 Remix 中创建 my_smart_contract 待处理" - Creation of my_smart_contract pending in Remix 得到 parsererror 我在 remix 上写 inheritance solidity 代码我得到了错误 - getting parsererror I write inheritance solidity code on remix i got error 我可以把它写在 remix ide 中吗? - Can I write it in remix ide? 尝试运行智能合约时出现解析器错误 - Parser error when trying to run a smart contract 无法部署智能合约重新混音 - Cannot deploy smart contract In remix 我在松露中遇到错误,但在在线编译器(混音)中,此关键字和 selfdestruct 函数中没有显示任何错误 - i am getting the error in truffle but in online compiler(remix)there is not showing any error in this keyword and selfdestruct function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM