user3390730
user3390730

Reputation: 1

Why does this function fail to withdraw ether from a smart contract?

I used the following code which I thought would be able to withdraw any ether that was deposited to the smart contract. Can you help explain why this might not work?

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

I am having issues withdrawing the ether and was wondering which part of the code is preventing me from doing so.

Upvotes: 0

Views: 598

Answers (1)

Nithin
Nithin

Reputation: 63

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

use this code

Upvotes: 1

Related Questions