Erc-20

合約執行期間交易被撤銷回复_______R和在和r噸和dReverted

  • November 1, 2020

我將 ETH 發送到合約地址,交易“失敗”說:Warning! Error encountered during contract execution [Reverted].

合約地址和交易失敗在這裡:

https://rinkeby.etherscan.io/tx/0x28a0a0f7eb8cf863afb4a9a2425648d2d9693e39793f0f9cc01d006374808370

ICO 代幣合約程式碼:-

pragma solidity ^0.4.24;
import "./DappToken.sol";


contract ICOToken is DappToken {

  string public name = 'ICOToken';
  string public symbol = 'ITK';
  uint256 public decimals = 18;
  uint256 public totalSupply;
  address public crowdsaleAddress;
  address public owner;
  uint256 public ICOEndTime = 1541246755;
  uint256 public balance;

  modifier onlyCrowdsale {
     require(msg.sender == crowdsaleAddress);
     _;
  }

  modifier onlyOwner {
     require(msg.sender == owner);
     _;
  }

//   modifier afterCrowdsale {
//  require(now > ICOEndTime || msg.sender == crowdsaleAddress);
//      _;
//  }

  constructor (uint256 _tokenSupply) public DappToken() {
     totalSupply = _tokenSupply;
     balanceOf[msg.sender] = _tokenSupply;
     owner = msg.sender;
  }


  function setCrowdsale(address _crowdsaleAddress) public onlyOwner  {

     require(_crowdsaleAddress != address(0));
     crowdsaleAddress = _crowdsaleAddress;

  }


   function buyTokens(address _receiver, uint256 _amount) public  {

     require(_receiver != address(0));
     require(_amount > 0);
     transfer(_receiver, _amount);


  }

//       /// @notice Override the functions to not allow token transfers until the end of the ICO
//   function transfer(address _to, uint256 _value) public afterCrowdsale returns(bool) {

//       return super.transfer(_to, _value);

//   }


//   /// @notice Override the functions to not allow token transfers until the end of the ICO
//   function transferFrom(address _from, address _to, uint256 _value) public afterCrowdsale returns(bool) {

//       return super.transferFrom(_from, _to, _value);

//   }


//   /// @notice Override the functions to not allow token transfers until the end of the ICO
//   function approve(address _spender, uint256 _value) public afterCrowdsale returns(bool) {

//       return super.approve(_spender, _value);
//   }

//   /// @notice Override the functions to not allow token transfers until the end of the ICO

//   function increaseApproval(address _spender, uint _addedValue) public afterCrowdsale returns(bool success) {

//       return super.increaseApproval(_spender, _addedValue);
//   }

//   /// @notice Override the functions to not allow token transfers until the end of the ICO

//   function decreaseApproval(address _spender, uint _subtractedValue) public afterCrowdsale returns(bool success) {

//       return super.decreaseApproval(_spender, _subtractedValue);
//   }

//   function emergencyExtract() external onlyOwner {

//       owner.transfer(address(this).balance);
//   }

}

像這樣的眾籌合約程式碼:-

   pragma solidity ^0.4.24;
import "./ICOToken.sol";

contract Crowdsale {
  bool public icoCompleted;
  uint256 public icoStartTime = 1538567825; // 3 oct 2018 11.57 AM UTC;
  uint256 public icoEndTime = 1541246755;  // 3 nov 2018 11.57 Am UTC;
  uint256 public tokenRate;
  uint256 public fundingGoal;
  address public owner;
  ICOToken public token;
  uint256 public tokensRaised;
  uint256 public etherRaised;
  uint256 public etherUsed = msg.value;
  uint256 public tokensToBuy;


  modifier whenIcoCompleted {
     require(icoCompleted);
     _;
  }

   modifier onlyOwner {
     require(msg.sender == owner);
     _;
  }

  function () public payable {
      buy();
  }

    constructor(uint256 _tokenRate, address _tokenAddress, uint256 _fundingGoal) public {
     require(icoStartTime != 0 &&
     icoEndTime != 0 &&
     icoStartTime < icoEndTime &&
     _tokenRate != 0 &&
     _tokenAddress != address(0) &&
     _fundingGoal != 0);
     tokenRate = _tokenRate;
     token = ICOToken(_tokenAddress);
     fundingGoal = _fundingGoal;
     owner = msg.sender;
     etherUsed;
     tokensToBuy;
  }

   function buy() public payable {

   //   require(tokensRaised < fundingGoal);
   //   require(now < icoEndTime && now > icoStartTime);

     etherUsed = msg.value;

     tokensToBuy = etherUsed * (10 ** token.decimals()) / 1 ether * tokenRate;

   //   Check if we have reached and exceeded the funding goal to refund the exceeding tokens and ether

   //   if(tokensRaised + tokensToBuy > fundingGoal) {

   //      uint256 exceedingTokens = tokensRaised + tokensToBuy - fundingGoal;
   //      uint256 exceedingEther;

   // //   Convert the exceedingTokens to ether and refund that ether
   //      exceedingEther = exceedingTokens * 1 ether / tokenRate / token.decimals();

   //      msg.sender.transfer(exceedingEther);

   //     //   Change the tokens to buy to the new number
   //      tokensToBuy -= exceedingTokens;

   //     //   Update the counter of ether used
   //      etherUsed -= exceedingEther;

   //   }
     // Send the tokens to the buyer
     token.buyTokens(msg.sender, tokensToBuy);

     // Increase the tokens raised and ether raised state variables
     tokensRaised += tokensToBuy;
     etherRaised += etherUsed;
  }


  function extractEther() public whenIcoCompleted onlyOwner {
      owner.transfer(address(this).balance);
  }

}

我還在 remix 上進行了調試,發現當最終使用者通過 metamask 錢包支付金額時,這個 msg.value 沒有儲存在用於眾籌智能合約的 etherused 變數中。所以令牌不能轉移到接收者。

那麼我該如何解決這個問題?請幫我。

謝謝。

它看起來像在buy()執行時呼叫token.buyTokens().

buyTokens()依次呼叫transfer()。絕大多數傳輸函式會在傳輸之前檢查使用者餘額,所以我假設您的超級實現也會這樣做。

因此,由於在transfer()msg.sender的眾籌合約中,眾籌合約必須持有足夠的代幣來進行轉移,但情況似乎並非如此。

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