我在withdrawmoney() 函数中遇到了这个问题

时间:2021-03-08 08:04:30

标签: solidity

这是我的代码:

pragma solidity ^0.8.0;

contract sendMoney {
    
    uint public balanceRecieved;
    
    function recieveMoney()public payable {
        balanceRecieved += msg.value;
    }
    
    function getBalance() public view returns(uint) {
        return address(this).balance;
    }
    
    function withdrawMoney() public {
        to payable(msg.sender)   = address;
        to.transfer(this.getBalance());
    }
}

这是我得到的错误:

ParserError: Expected ';' but got 'payable' --> browser/sendMoney.sol:16:12: | 16 | to payable(msg.sender) = address; | ^^^^^^^

1 个答案:

答案 0 :(得分:0)

您在这一行的语法不正确:

to payable(msg.sender)   = address;

正确的语法:

address payable to = payable(msg.sender);