Remix

錯誤:所需的氣體超過限額或在 chrome-extension 上總是失敗的交易

  • March 11, 2022

我正在使用 Remix、Metamask、ROPSTEN 並且無法部署任何合約……總是收到相同的消息……它曾經工作……不再工作……發生在不同的機器上,發生在 Chrome 或 Firefox …似乎與估計程序有關…

氣體估算失敗

氣體估計錯誤並顯示以下消息(見下文)。事務執行可能會失敗。是否要強制發送?錯誤:在 chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:1723632 在 chrome-extension 需要的氣體超過限額或總是失敗交易

讓我知道您是否有類似的設置並且可以正常工作…或任何已知問題…

謝謝 !

這是程式碼:

pragma solidity ^0.4.20;
contract Ballot {

   struct Voter {
       uint weight;
       bool voted;
       uint8 vote;
       address delegate;
   }
   struct Proposal {
       uint voteCount;
   }

   address chairperson;
   mapping(address => Voter) voters;
   Proposal[] proposals;

   /// Create a new ballot with $(_numProposals) different proposals.
   function Ballot(uint8 _numProposals) public {
       chairperson = msg.sender;
       voters[chairperson].weight = 1;
       proposals.length = 3;
   }

   /// Give $(toVoter) the right to vote on this ballot.
   /// May only be called by $(chairperson).
   function giveRightToVote(address toVoter) public {
       if (msg.sender != chairperson || voters[toVoter].voted) return;
       voters[toVoter].weight = 1;
   }

   /// Delegate your vote to the voter $(to).
   function delegate(address to) public {
       Voter storage sender = voters[msg.sender]; // assigns reference
       if (sender.voted) return;
       while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender)
           to = voters[to].delegate;
       if (to == msg.sender) return;
       sender.voted = true;
       sender.delegate = to;
       Voter storage delegateTo = voters[to];
       if (delegateTo.voted)
           proposals[delegateTo.vote].voteCount += sender.weight;
       else
           delegateTo.weight += sender.weight;
   }

   /// Give a single vote to proposal $(toProposal).
   function vote(uint8 toProposal) public {
       Voter storage sender = voters[msg.sender];
       if (sender.voted || toProposal >= proposals.length) return;
       sender.voted = true;
       sender.vote = toProposal;
       proposals[toProposal].voteCount += sender.weight;
   }

   function winningProposal() public constant returns (uint8 _winningProposal) {
       uint256 winningVoteCount = 0;
       for (uint8 prop = 0; prop < proposals.length; prop++)
           if (proposals[prop].voteCount > winningVoteCount) {
               winningVoteCount = proposals[prop].voteCount;
               _winningProposal = prop;
           }
   }
}

氣體限制:3000000 價值:1 乙太幣

看看你能不能把它部署到 ROPSTEN…

您的程式碼缺少該constructor()功能,請參見此處

您的程式碼在我的機器上執行良好。

1)我猜 Remix 編譯有一些問題,使用相同的程式碼創建一個新的 Solidity 文件並重新部署它可能會有所幫助。2) 另外,嘗試重新載入 Chrome(Remix 標籤) 3) 否則,重新安裝 Metamask。

希望能幫助到你!

引用自:https://ethereum.stackexchange.com/questions/56606