为什么此功能无法从智能合约中提取以太币?

时间:2018-12-28 02:16:08

标签: ethereum solidity smartcontracts erc20

我使用了以下代码,我认为该代码将能够提取出任何已存入智能合约的以太币。您能帮忙解释一下为什么这可能行不通吗?

function withdraw() public {
        require(owner == msg.sender);
        msg.sender.transfer(address(this).balance);
}

我在提取以太币时遇到问题,并且想知道代码的哪一部分阻止了我这样做。

1 个答案:

答案 0 :(得分:0)

 function withdraw(uint amount) public payable{
    require(address(this).balance >= amount);
    msg.sender.transfer(amount);   
}

使用此代码