Solidity

Remix:此合約未實現所有功能,因此無法創建

  • October 30, 2019

我是新來的,使用 openzeppelin 框架 2.2.0 編寫程式碼。使用solidity 0.5.8編譯時沒有發生錯誤。但是當我要部署合約時,我沒有字節碼,無法與合約互動“這個合約沒有實現所有功能,因此無法創建。”

contract SampleCrowdsale is ERC20Detailed, Ownable, FinalizableCrowdsale, TokenTimelock {
   constructor () public ERC20Detailed("SampleCrowdsale", "SCRT", 15) {

   }

   mapping (address => uint256) private balances;

   uint256 public totalSupply = 1000000000000000000000000; 
   uint256 public constant TOKENS_SALE_HARD_CAP = 650000000000000000000000;
   uint256 public constant BASE_RATE = 32500000;

   uint64 private constant dateHOTSale = 1517961600;
   uint64 private constant dateSaleA = 1557991800 - 7 hours;
   uint64 private constant dateSaleB = 1557993600 - 7 hours;
   uint64 private constant dateSaleC = 1557995400 - 7 hours;
   uint64 private constant dateSaleD = 1557999000 - 7 hours;
   uint64 private constant date17May2019 = 1557999180 - 7 hours;

   uint256[4] private roundCaps = [
       100000000000000000000000, 
       250000000000000000000000,
       450000000000000000000000, 
       650000000000000000000000 
   ];
   uint8[4] private roundDiscountPercentages = [50, 25, 12, 6];

   uint64 private constant dateTeamTokensLockedTill = 1557999360 - 7 hours;

   bool public _finalized = false;

   address public timelockContractAddress;

   modifier inProgress {
       require(totalSupply < TOKENS_SALE_HARD_CAP && !_finalized && now >= dateHOTSale);
       _;
   }

   modifier beforeEnd {
       require(!_finalized);
       _;
   }

   function sampleCrowdSale() public {
       }

   modifier tradingOpen {
       require(_finalized);
       _;
   }

   function () external payable {
       purchaseTokens(msg.sender);
   }

   function purchaseTokens(address _beneficiary) public payable inProgress {
       require(msg.value >= 0.05 ether);
       uint256 tokens = computeTokenAmount(msg.value);
       require(totalSupply.add(tokens) <= TOKENS_SALE_HARD_CAP);
       doIssueTokens(_beneficiary, tokens);
       address(0).transfer(address(this).balance);
   }

   function issueTokens(address _beneficiary, uint256 _tokens) public onlyOwner beforeEnd {
       doIssueTokens(_beneficiary, _tokens);
   }

   function doIssueTokens(address _beneficiary, uint256 _tokens) internal {
       require(_beneficiary != address(0));

       totalSupply = totalSupply.add(_tokens);
       balances[_beneficiary] = balances[_beneficiary].add(_tokens);

       emit Transfer(address(0), _beneficiary, _tokens);
   }

   function price() public view returns (uint256 tokens) {
       return computeTokenAmount(1 ether);
   }

   function computeTokenAmount(uint256 ethAmount) internal view returns (uint256 tokens) {
       uint256 tokenBase = (ethAmount.mul(BASE_RATE)/10000000000000)*10000000000;//18 decimals to 15 decimals, set precision to 5 decimals
       uint8 roundNum = currentRoundIndex();
       tokens = tokenBase.mul(100)/(100 - (roundDiscountPercentages[roundNum]));
       while(tokens.add(totalSupply) > roundCaps[roundNum] && roundNum < 4){
          roundNum++;
          tokens = tokenBase.mul(100)/(100 - (roundDiscountPercentages[roundNum]));
       }
   }

   function currentRoundIndex() internal view returns (uint8 roundNum) {
       roundNum = currentRoundIndexByDate();

       while(roundNum < 4 && totalSupply > roundCaps[roundNum]) {
           roundNum++;
       }
   }

   function currentRoundIndexByDate() internal view returns (uint8 roundNum) {
       require(now <= date17May2019);
       if(now > dateSaleD) return 4;
       if(now > dateSaleC) return 3;
       if(now > dateSaleB) return 2;
       if(now > dateSaleA) return 1;
       else return 0;
   }

   function finalize() public onlyOwner beforeEnd {
       uint256 lockedTokens = 230000000000000000000000;
       uint256 partnerTokens = 260000000000000000000000;

       issueLockedTokens(lockedTokens);
       issuePartnerTokens(partnerTokens);

       totalSupply = totalSupply.add(lockedTokens+partnerTokens);

       _finalized = true;

       address(0).transfer(address(this).balance);
   }

   function issueLockedTokens(uint lockedTokens) internal {
       TokenTimelock lockedTeamTokens = new TokenTimelock(this, address(0), dateTeamTokensLockedTill);
       timelockContractAddress = address(lockedTeamTokens);
       balances[timelockContractAddress] = balances[timelockContractAddress].add(lockedTokens);
       emit Transfer(address(0), timelockContractAddress, lockedTokens);
   }

   function issuePartnerTokens(uint partnerTokens) internal{
       balances[address(0)] = partnerTokens;
       emit Transfer(address(0), address(0), partnerTokens);
   }

   function transferFrom(address _from, address _to, uint256 _value) public tradingOpen returns (bool) {
       return transferFrom(_from, _to, _value);
   }

   function transfer(address _to, uint256 _value) public tradingOpen returns (bool) {
       return transfer(_to, _value);
   }
}

如果您從 Remix IDE 部署合約,您應該 在 Run Tab 中 選擇SampleCrowdsale 。

混音 IDE

消息意味著它所說的。

考慮到您正在使用的程式碼的數量和復雜性,這不是一個學習的好項目。我希望這只是為了練習,您不會考慮誘使其他人將他們的資金交給您不完全理解的程式碼。

有很多程式碼需要探索,所以我將解釋你應該尋找什麼。

當一個合約從另一個合約繼承和未定義的功能時,它承諾提供一個功能實現。具有未定義函式的合約可以編譯,但無法部署。這是因為具有不知道該做什麼的功能的合約在鏈上沒有意義。

在 Remix 中研究這個小例子。

pragma solidity 0.5.1;

contract Interface {
   function something() public;
   function somethingElse() public;
}

// does not implement all functions
contract Undeployable is Interface {
   uint x;
   function something() public {
       // do something
       x=1;
   }
}

contract Deployable is Undeployable {
   uint y;
   function somethingElse() public {
       // do something
       y=1;
   }
}

函式內容只是無關緊要的存根。繼承圖以實現兩個未定義函式的承諾開始。其中一個函式是在下一個實現缺失函式並繼承Undeployable的合約中定義並獲取的。這履行了從繼承開始的承諾。是,以防萬一不清楚。Deployable``something()``Interface``Deployable``Interface

因此,您正在尋找一些未實現的東西,可能是在界面中。無論如何,這是一個安全系統。在實現規範中定義的所有功能之前,您的合約不會呈現與 ERC20 兼容的介面。這種安全停止的目的是使用描述必要功能的介面契約來建構程式碼。發現缺少的功能可能會花費一些時間,但這是您需要查明的。

希望能幫助到你。

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