Ethereum 以太坊,众筹向钱包返还0.00代币

Ethereum 以太坊,众筹向钱包返还0.00代币,ethereum,solidity,Ethereum,Solidity,我试图在以太坊测试网建立一个基本的众筹,我使用的代码是在 按照该指南中所述的步骤进行操作 第一个问题是,由于第一行代码,以太坊钱包不接受要编译的代码: contract token{函数传输(地址接收方,uint金额){} 具体地说,它的函数返回未使用的局部变量的警告,并且不会编译。除了在函数中定义空变量外,还有其他解决方法吗 第二个问题是,在部署了上面提到的修改之后,它就可以工作了。但当它向发送以太的钱包发送代币时,金额始终锁定在0.00代币 完整代码: pragma solidity ^0

我试图在以太坊测试网建立一个基本的众筹,我使用的代码是在

按照该指南中所述的步骤进行操作

第一个问题是,由于第一行代码,以太坊钱包不接受要编译的代码:
contract token{函数传输(地址接收方,uint金额){}

具体地说,它的函数返回未使用的局部变量的警告,并且不会编译。除了在函数中定义空变量外,还有其他解决方法吗

第二个问题是,在部署了上面提到的修改之后,它就可以工作了。但当它向发送以太的钱包发送代币时,金额始终锁定在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 a 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;
            }
        }
    }
}

编辑:我忘了提到实现这一点的步骤,即令牌创建/股东协会使用指南中提供的代码。

我遇到了同样的问题。我通过实际定义
transfer
函数解决了这个问题,以太坊的示例提供了一个空函数

我替换了这个:

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的以太发送到批量销售合同


希望有帮助

所有代码段都应该缩进,以便堆栈溢出UI正确显示