2017-07-03 48 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的以太值。

希望它有帮助!