2017-07-03 29 views
0

進出口試圖設置基本crowdsale復仇testnet和使用密實代碼IM是按照與在所描述的在復仇,crowdsale在返回0.00令牌錢包

https://ethereum.org/crowdsale#the-code

與步驟中找到的基本實施例指南。

問題首先是,復仇錢包犯規接受代碼是編譯由於第一線

contract token { function transfer(address receiver, uint amount){ } } 

更具體的函數返回未使用的局部變量的警告,並不會編譯是有辦法除了在函數內部定義空變量之外呢?

第二個是在其部署了上述修改之後它可以工作,但是當它將令牌發送給發送以太的錢包時,金額始終鎖定在0.00令牌。

全碼:

pragma solidity ^0.4.2; 
contract token { function transfer(address receiver, uint amount){ receiver; amount; } } 

contract Crowdsale { 
    address public beneficiary; 
    uint public fundingGoal; uint public amountRaised; uint public deadline; uint public price; 
    token public tokenReward; 
    mapping(address => uint256) public balanceOf; 
    bool fundingGoalReached = false; 
    event GoalReached(address beneficiary, uint amountRaised); 
    event FundTransfer(address backer, uint amount, bool isContribution); 
    bool crowdsaleClosed = false; 

    /* data structure to hold information about campaign contributors */ 

    /* at initialization, setup the owner */ 
    function Crowdsale(
     address ifSuccessfulSendTo, 
     uint fundingGoalInEthers, 
     uint durationInMinutes, 
     uint etherCostOfEachToken, 
     token addressOfTokenUsedAsReward 
    ) { 
     beneficiary = ifSuccessfulSendTo; 
     fundingGoal = fundingGoalInEthers * 1 ether; 
     deadline = now + durationInMinutes * 1 minutes; 
     price = etherCostOfEachToken * 1 ether; 
     tokenReward = token(addressOfTokenUsedAsReward); 
    } 

    /* The function without name is the default function that is called whenever anyone sends funds to a contract */ 
    function() payable { 
     if (crowdsaleClosed) throw; 
     uint amount = msg.value; 
     balanceOf[msg.sender] = amount; 
     amountRaised += amount; 
     tokenReward.transfer(msg.sender, amount/price); 
     FundTransfer(msg.sender, amount, true); 
    } 

    modifier afterDeadline() { if (now >= deadline) _; } 

    /* checks if the goal or time limit has been reached and ends the campaign */ 
    function checkGoalReached() afterDeadline { 
     if (amountRaised >= fundingGoal){ 
      fundingGoalReached = true; 
      GoalReached(beneficiary, amountRaised); 
     } 
     crowdsaleClosed = true; 
    } 


    function safeWithdrawal() afterDeadline { 
     if (!fundingGoalReached) { 
      uint amount = balanceOf[msg.sender]; 
      balanceOf[msg.sender] = 0; 
      if (amount > 0) { 
       if (msg.sender.send(amount)) { 
        FundTransfer(msg.sender, amount, false); 
       } else { 
        balanceOf[msg.sender] = amount; 
       } 
      } 
     } 

     if (fundingGoalReached && beneficiary == msg.sender) { 
      if (beneficiary.send(amountRaised)) { 
       FundTransfer(beneficiary, amountRaised, false); 
      } else { 
       //If we fail to send the funds to beneficiary, unlock funders balance 
       fundingGoalReached = false; 
      } 
     } 
    } 
} 

編輯忘了提及導致了這一點又名令牌創建/股東協會工作的代碼的步驟爲先導的提供。

+0

所有的代碼片段都應該縮進,以便通過堆棧溢出UI正確顯示 – Jerome

回答

1

我遇到了同樣的問題。我通過實際定義transfer函數來解決它,因爲來自ethereum.org的示例提供了一個空例。

我換成這樣的:

contract token { function transfer(address receiver, uint amount){ } } 

通過這樣的:

contract token {  
    event Transfer(address indexed from, address indexed to, uint256 value); 
    function transfer(address _to, uint256 _value) { 
     if (_to == 0x0) throw; 
     Transfer(msg.sender, _to, _value); 
    } 

} 

關於第二個問題,你實際上有一個確認創建令牌實際上發出?你有多少乙醚被送到人羣銷售合同?看起來你的令牌使用了兩位小數,如果你像例子中那樣定義了「每個令牌的以太成本」爲5,那麼你不應該向派衆合同發送小於0.05的以太值。

希望它有幫助!