如何使用Solidity转移余额?

问题描述

我正在使用Solidity开发彩票智能合约(教程)。无效的代码段涉及以下“随机”获胜者的选择:

pragma solidity ^0.4.17;

function pickWinner() public restricted {
    uint index = random() % players.length;
    players[index].transfer(this.balance);
    players = new address[](0);
}

我在remix以太坊平台上对其进行测试时收到的错误消息是:

transact to Lottery.pickWinner errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.

如果看起来需要付款才能将奖金发送回赢家,那么如何将其包括在代码中?我已经尝试过使用msg.value,如下所示:

msg.value = 0.0001 ether;
players[index].transfer(this.balance);

,我仍然收到错误消息。如何解决? 谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)