How to Withdraw Ether from a Contract

contract-developmentethereum-wallet-dappsolidity

I've been playing with Token contracts, so far so good, however once the Ether is sent and the tokens created, what happens to the Ether?

I have some Ether on the contract address, how do I withdraw it?

I guess it's not about the contract code but about the interface, I've been using Ethereum Wallet. The send funds screen only allows to fund the contract, not send from it.

Best Answer

The function would be something like this:

pragma solidity >=0.8.0;

function withdraw() {
    payable(msg.sender).transfer(address(this).balance);
}

Just make sure you only allow yourself to access it

Related Topic